From f9756ca203a06fa60413ef1a96416d87b9dc1a6b Mon Sep 17 00:00:00 2001 From: eilers Date: Wed, 16 Oct 2002 10:52:40 +0000 Subject: Added some docu to the interface and now using the cache infrastucture by zecke.. :) --- (limited to 'libopie2/opiepim') diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index 50ea329..12a75ba 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h @@ -17,6 +17,9 @@ * ===================================================================== * 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 * @@ -56,7 +59,8 @@ 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; @@ -75,6 +79,10 @@ class OContactAccessBackend_XML : public OContactAccessBackend { } bool save() { + + if ( !m_changed ) + return true; + QString strNewFile = m_fileName + ".new"; QFile f( strNewFile ); if ( !f.open( IO_WriteOnly|IO_Raw ) ) @@ -123,6 +131,8 @@ class OContactAccessBackend_XML : public OContactAccessBackend { /* The journalfile should be removed now... */ removeJournal(); + + m_changed = false; return true; } @@ -145,6 +155,7 @@ class OContactAccessBackend_XML : public OContactAccessBackend { void clear () { m_contactList.clear(); + m_changed = false; } @@ -275,11 +286,16 @@ class OContactAccessBackend_XML : public OContactAccessBackend { //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 it; @@ -300,6 +316,8 @@ class OContactAccessBackend_XML : public OContactAccessBackend { bool remove ( int uid ) { + m_changed = true; + bool found = false; QValueListIterator it; for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ @@ -553,6 +571,7 @@ class OContactAccessBackend_XML : public OContactAccessBackend { } protected: + bool m_changed; QString m_journalName; QString m_fileName; QString m_appName; diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index e8c0a45..2ca0283 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -21,6 +21,9 @@ * ===================================================================== * 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 * @@ -62,8 +65,7 @@ OContactAccess::OContactAccess ( const QString appname, const QString , OContactAccessBackend* end, bool autosync ): - OPimAccessTemplate( end ), - m_changed ( false ) + OPimAccessTemplate( 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..). @@ -94,15 +96,10 @@ 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 () { @@ -110,19 +107,15 @@ bool OContactAccess::save () * Data. This will remove added items which is unacceptable ! * Therefore: Reload database and merge the data... */ - if ( m_backEnd->wasChangedExternally() ) + if ( OPimAccessTemplate::wasChangedExternally() ) reload(); - if ( m_changed ){ - bool status = m_backEnd->save(); - if ( !status ) return false; + bool status = OPimAccessTemplate::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; } @@ -137,29 +130,6 @@ 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 { @@ -167,11 +137,6 @@ bool OContactAccess::wasChangedExternally()const } -bool OContactAccess::reload() -{ - return ( m_backEnd->reload() ); -} - void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) { if ( msg == "addressbookUpdated()" ){ diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index adc66cf..da9c942 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h @@ -17,6 +17,9 @@ * ===================================================================== * 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 * @@ -91,51 +94,12 @@ class OContactAccess: public QObject, public OPimAccessTemplate */ bool hasQuerySettings ( int querySettings ) const; - /** Add Contact to database. - * @param newcontact The contact to add. - * @return true if added successfully. - */ - bool add (const OContact& newcontact); - - /** Replace contact. - * Replaces given contact with contact with the user id uid. - * @param uid The user ID - * @param contact The new contact - * @return true if successful. - */ - bool replace ( const OContact& contact ); - - /** Remove contact. - * Removes contact with the user id uid. - * @param The contact to remove - * @return true if successful. - */ - bool remove ( const OContact& t ); - - /** Remove contact. - * Removes contact with the user id uid. - * @param The user id of the contact to remove - * @return true 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. @@ -158,7 +122,6 @@ class OContactAccess: public QObject, public OPimAccessTemplate // 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/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 3e1f393..50cb1e4 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -37,18 +37,24 @@ public: */ 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; @@ -59,7 +65,7 @@ public: virtual List allRecords()const; /** - * queryByExample) + * queryByExample. * @see otodoaccess, ocontactaccess */ virtual List queryByExample( const T& t, int querySettings ); @@ -83,22 +89,30 @@ public: /** * add T to the backend + * @param t The item to add. + * @return true 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 true if successful. */ virtual bool remove( const T& t ); /** * remove the OPimRecord with uid + * @param uid The ID of the item to remove + * @return true if successful. */ virtual bool remove( int uid ); /** * replace T from backend + * @param t The item to replace + * @return true if successful. */ virtual bool replace( const T& t) ; @@ -142,7 +156,8 @@ bool OPimAccessTemplate::load() { } template bool OPimAccessTemplate::reload() { - return m_backEnd->reload(); + invalidateCache(); // zecke: I think this should be added (se) + return m_backEnd->reload(); } template bool OPimAccessTemplate::save() { -- cgit v0.9.0.2