summaryrefslogtreecommitdiff
path: root/libopie
Side-by-side diff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccess.cpp57
-rw-r--r--libopie/pim/ocontactaccess.h43
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h21
-rw-r--r--libopie/pim/opimaccesstemplate.h27
4 files changed, 55 insertions, 93 deletions
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp
index e8c0a45..2ca0283 100644
--- a/libopie/pim/ocontactaccess.cpp
+++ b/libopie/pim/ocontactaccess.cpp
@@ -18,12 +18,15 @@
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.5 2002/10/16 10:52:40 eilers
+ * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
+ *
* Revision 1.4 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.3 2002/10/07 17:34:24 eilers
* added OBackendFactory for advanced backend access
*
@@ -59,14 +62,13 @@
#include "ocontactaccessbackend_xml.h"
OContactAccess::OContactAccess ( const QString appname, const QString ,
OContactAccessBackend* end, bool autosync ):
- OPimAccessTemplate<OContact>( end ),
- m_changed ( false )
+ OPimAccessTemplate<OContact>( end )
{
/* take care of the backend. If there is no one defined, we
* will use the XML-Backend as default (until we have a cute SQL-Backend..).
*/
if( end == 0 ) {
qWarning ("Using BackendFactory !");
@@ -91,41 +93,32 @@ OContactAccess::OContactAccess ( const QString appname, const QString ,
}
OContactAccess::~OContactAccess ()
{
/* The user may forget to save the changed database, therefore try to
* do it for him..
*/
- if ( m_changed )
- save();
+ save();
// delete m_backEnd; is done by template..
}
-bool OContactAccess::load()
-{
- return ( m_backEnd->load() );
-}
bool OContactAccess::save ()
{
/* If the database was changed externally, we could not save the
* Data. This will remove added items which is unacceptable !
* Therefore: Reload database and merge the data...
*/
- if ( m_backEnd->wasChangedExternally() )
+ if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
reload();
- if ( m_changed ){
- bool status = m_backEnd->save();
- if ( !status ) return false;
+ bool status = OPimAccessTemplate<OContact>::save();
+ if ( !status ) return false;
- m_changed = false;
- /* Now tell everyone that new data is available.
- */
- QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
-
- }
+ /* Now tell everyone that new data is available.
+ */
+ QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
return true;
}
const uint OContactAccess::querySettings()
{
@@ -134,47 +127,19 @@ const uint OContactAccess::querySettings()
bool OContactAccess::hasQuerySettings ( int querySettings ) const
{
return ( m_backEnd->hasQuerySettings ( querySettings ) );
}
-bool OContactAccess::add ( const OContact& newcontact )
-{
- m_changed = true;
- return ( m_backEnd->add ( newcontact ) );
-}
-
-bool OContactAccess::replace ( const OContact& contact )
-{
- m_changed = true;
- return ( m_backEnd->replace ( contact ) );
-}
-
-bool OContactAccess::remove ( const OContact& t )
-{
- m_changed = true;
- return ( m_backEnd->remove ( t.uid() ) );
-}
-
-bool OContactAccess::remove ( int uid )
-{
- m_changed = true;
- return ( m_backEnd->remove ( uid ) );
-}
bool OContactAccess::wasChangedExternally()const
{
return ( m_backEnd->wasChangedExternally() );
}
-bool OContactAccess::reload()
-{
- return ( m_backEnd->reload() );
-}
-
void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
{
if ( msg == "addressbookUpdated()" ){
qWarning ("OContactAccess: Received addressbokUpdated()");
emit signalChanged ( this );
} else if ( msg == "flush()" ) {
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h
index adc66cf..da9c942 100644
--- a/libopie/pim/ocontactaccess.h
+++ b/libopie/pim/ocontactaccess.h
@@ -14,12 +14,15 @@
* ToDo: Define enum for query settings
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.3 2002/10/16 10:52:40 eilers
+ * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
+ *
* Revision 1.2 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.1 2002/09/27 17:11:44 eilers
* Added API for accessing the Contact-Database ! It is compiling, but
* please do not expect that anything is working !
@@ -88,57 +91,18 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
/** Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
bool hasQuerySettings ( int querySettings ) const;
- /** Add Contact to database.
- * @param newcontact The contact to add.
- * @return <i>true</i> if added successfully.
- */
- bool add (const OContact& newcontact);
-
- /** Replace contact.
- * Replaces given contact with contact with the user id <i>uid</i>.
- * @param uid The user ID
- * @param contact The new contact
- * @return <i>true</i> if successful.
- */
- bool replace ( const OContact& contact );
-
- /** Remove contact.
- * Removes contact with the user id <i>uid</i>.
- * @param The contact to remove
- * @return <i>true</i> if successful.
- */
- bool remove ( const OContact& t );
-
- /** Remove contact.
- * Removes contact with the user id <i>uid</i>.
- * @param The user id of the contact to remove
- * @return <i>true</i> if successful.
- */
- bool remove ( int uid );
-
- /** Load Database *
- */
- bool load();
-
/**
* if the resource was changed externally.
* You should use the signal instead of polling possible changes !
*/
bool wasChangedExternally()const;
- /** Reload database.
- * You should execute this function if the external database
- * was changed.
- * This function will load the external database and afterwards
- * rejoin the local changes. Therefore the local database will be set consistent.
- */
- bool reload();
/** Save contacts database.
* Save is more a "commit". After calling this function, all changes are public available.
* @return true if successful
*/
bool save();
@@ -155,13 +119,12 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
private:
// class OContactAccessPrivate;
// OContactAccessPrivate* d;
OContactAccessBackend *m_backEnd;
bool m_loading:1;
- bool m_changed;
private slots:
void copMessage( const QCString &msg, const QByteArray &data );
};
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index 50ea329..12a75ba 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -14,12 +14,15 @@
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.4 2002/10/16 10:52:40 eilers
+ * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
+ *
* Revision 1.3 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.2 2002/10/07 17:34:24 eilers
* added OBackendFactory for advanced backend access
*
@@ -53,13 +56,14 @@
using namespace Opie;
/* the default xml implementation */
class OContactAccessBackend_XML : public OContactAccessBackend {
public:
- OContactAccessBackend_XML ( QString appname, QString filename = 0l )
+ OContactAccessBackend_XML ( QString appname, QString filename = 0l ):
+ m_changed( false )
{
m_appName = appname;
/* Set journalfile name ... */
m_journalName = getenv("HOME");
m_journalName +="/.abjournal" + appname;
@@ -72,12 +76,16 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
/* Load Database now */
load ();
}
bool save() {
+
+ if ( !m_changed )
+ return true;
+
QString strNewFile = m_fileName + ".new";
QFile f( strNewFile );
if ( !f.open( IO_WriteOnly|IO_Raw ) )
return false;
int total_written;
@@ -120,12 +128,14 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
// remove the tmp file...
QFile::remove( strNewFile );
}
/* The journalfile should be removed now... */
removeJournal();
+
+ m_changed = false;
return true;
}
bool load () {
m_contactList.clear();
@@ -142,12 +152,13 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
return true;
}
void clear () {
m_contactList.clear();
+ m_changed = false;
}
bool wasChangedExternally()
{
QFileInfo fi( m_fileName );
@@ -272,17 +283,22 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
bool add ( const OContact &newcontact )
{
//qWarning("odefaultbackend: ACTION::ADD");
updateJournal (newcontact, OContact::ACTION_ADD);
addContact_p( newcontact );
+
+ m_changed = true;
+
return true;
}
bool replace ( const OContact &contact )
{
+ m_changed = true;
+
bool found = false;
QValueListIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ( (*it).uid() == contact.uid() ){
found = true;
@@ -297,12 +313,14 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
} else
return false;
}
bool remove ( int uid )
{
+ m_changed = true;
+
bool found = false;
QValueListIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ((*it).uid() == uid){
found = true;
break;
@@ -550,12 +568,13 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
QFile f ( m_journalName );
if ( f.exists() )
f.remove();
}
protected:
+ bool m_changed;
QString m_journalName;
QString m_fileName;
QString m_appName;
QValueList<OContact> m_contactList;
QDateTime m_readtime;
};
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h
index 3e1f393..50cb1e4 100644
--- a/libopie/pim/opimaccesstemplate.h
+++ b/libopie/pim/opimaccesstemplate.h
@@ -34,35 +34,41 @@ public:
/**
* load from the backend
*/
virtual bool load();
- /**
- * reload from the backend
+ /** Reload database.
+ * You should execute this function if the external database
+ * was changed.
+ * This function will load the external database and afterwards
+ * rejoin the local changes. Therefore the local database will be set consistent.
*/
virtual bool reload();
- /**
- * save to the backend
+ /** Save contacts database.
+ * Save is more a "commit". After calling this function, all changes are public available.
+ * @return true if successful
*/
virtual bool save();
/**
* if the resource was changed externally
+ * You should use the signal handling instead of polling possible changes !
+ * zecke: Do you implement a signal for otodoaccess ?
*/
bool wasChangedExternally()const;
/**
* return a List of records
* you can iterate over them
*/
virtual List allRecords()const;
/**
- * queryByExample)
+ * queryByExample.
* @see otodoaccess, ocontactaccess
*/
virtual List queryByExample( const T& t, int querySettings );
/**
* find the OPimRecord uid
@@ -80,28 +86,36 @@ public:
* clears the backend and invalidates the backend
*/
virtual void clear() ;
/**
* add T to the backend
+ * @param t The item to add.
+ * @return <i>true</i> if added successfully.
*/
virtual bool add( const T& t ) ;
/* only the uid matters */
/**
* remove T from the backend
+ * @param t The item to remove
+ * @return <i>true</i> if successful.
*/
virtual bool remove( const T& t );
/**
* remove the OPimRecord with uid
+ * @param uid The ID of the item to remove
+ * @return <i>true</i> if successful.
*/
virtual bool remove( int uid );
/**
* replace T from backend
+ * @param t The item to replace
+ * @return <i>true</i> if successful.
*/
virtual bool replace( const T& t) ;
/**
* @internal
*/
@@ -139,13 +153,14 @@ template <class T>
bool OPimAccessTemplate<T>::load() {
invalidateCache();
return m_backEnd->load();
}
template <class T>
bool OPimAccessTemplate<T>::reload() {
- return m_backEnd->reload();
+ invalidateCache(); // zecke: I think this should be added (se)
+ return m_backEnd->reload();
}
template <class T>
bool OPimAccessTemplate<T>::save() {
return m_backEnd->save();
}
template <class T>