summaryrefslogtreecommitdiff
path: root/libopie/pim/ocontactaccessbackend_xml.cpp
Side-by-side diff
Diffstat (limited to 'libopie/pim/ocontactaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.cpp171
1 files changed, 88 insertions, 83 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp
index c5a7820..661cd51 100644
--- a/libopie/pim/ocontactaccessbackend_xml.cpp
+++ b/libopie/pim/ocontactaccessbackend_xml.cpp
@@ -19,2 +19,7 @@
* $Log$
+ * Revision 1.5 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.4 2003/03/21 14:32:54 mickeyl
@@ -95,3 +100,3 @@
#include <qmap.h>
-#include <qdatetime.h>
+#include <qdatetime.h>
@@ -109,3 +114,3 @@ using namespace Opie;
-OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ):
+OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ):
m_changed( false )
@@ -118,3 +123,3 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString
m_appName = appname;
-
+
/* Set journalfile name ... */
@@ -122,3 +127,3 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString
m_journalName +="/.abjournal" + appname;
-
+
/* Expecting to access the default filename if nothing else is set */
@@ -128,3 +133,3 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString
m_fileName = filename;
-
+
/* Load Database now */
@@ -133,8 +138,8 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString
-bool OContactAccessBackend_XML::save()
+bool OContactAccessBackend_XML::save()
{
-
+
if ( !m_changed )
return true;
-
+
QString strNewFile = m_fileName + ".new";
@@ -143,3 +148,3 @@ bool OContactAccessBackend_XML::save()
return false;
-
+
int total_written;
@@ -176,3 +181,3 @@ bool OContactAccessBackend_XML::save()
out += " </Contacts>\n</AddressBook>\n";
-
+
// Write Footer
@@ -186,3 +191,3 @@ bool OContactAccessBackend_XML::save()
f.close();
-
+
// move the file over, I'm just going to use the system call
@@ -195,6 +200,6 @@ bool OContactAccessBackend_XML::save()
}
-
+
/* The journalfile should be removed now... */
removeJournal();
-
+
m_changed = false;
@@ -203,3 +208,3 @@ bool OContactAccessBackend_XML::save()
-bool OContactAccessBackend_XML::load ()
+bool OContactAccessBackend_XML::load ()
{
@@ -207,3 +212,3 @@ bool OContactAccessBackend_XML::load ()
m_uidToContact.clear();
-
+
/* Load XML-File and journal if it exists */
@@ -218,3 +223,3 @@ bool OContactAccessBackend_XML::load ()
load (m_journalName, true);
-
+
return true;
@@ -222,3 +227,3 @@ bool OContactAccessBackend_XML::load ()
-void OContactAccessBackend_XML::clear ()
+void OContactAccessBackend_XML::clear ()
{
@@ -233,5 +238,5 @@ bool OContactAccessBackend_XML::wasChangedExternally()
QFileInfo fi( m_fileName );
-
+
QDateTime lastmod = fi.lastModified ();
-
+
return (lastmod != m_readtime);
@@ -239,7 +244,7 @@ bool OContactAccessBackend_XML::wasChangedExternally()
-QArray<int> OContactAccessBackend_XML::allRecords() const
+QArray<int> OContactAccessBackend_XML::allRecords() const
{
QArray<int> uid_list( m_contactList.count() );
-
- uint counter = 0;
+
+ uint counter = 0;
QListIterator<OContact> it( m_contactList );
@@ -248,3 +253,3 @@ QArray<int> OContactAccessBackend_XML::allRecords() const
}
-
+
return ( uid_list );
@@ -255,3 +260,3 @@ OContact OContactAccessBackend_XML::find ( int uid ) const
OContact foundContact; //Create empty contact
-
+
OContact* found = m_uidToContact.find( QString().setNum( uid ) );
@@ -261,3 +266,3 @@ OContact OContactAccessBackend_XML::find ( int uid ) const
}
-
+
return ( foundContact );
@@ -265,6 +270,6 @@ OContact OContactAccessBackend_XML::find ( int uid ) const
-QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings,
+QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings,
const QDateTime& d )
{
-
+
QArray<int> m_currentQuery( m_contactList.count() );
@@ -272,3 +277,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
uint arraycounter = 0;
-
+
for( ; it.current(); ++it ){
@@ -292,3 +297,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
}
-
+
if ( queryDate->isValid() ){
@@ -298,3 +303,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
allcorrect = false;
- }
+ }
if ( settings & OContactAccess::DateMonth ){
@@ -302,3 +307,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
allcorrect = false;
- }
+ }
if ( settings & OContactAccess::DateDay ){
@@ -306,3 +311,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
allcorrect = false;
- }
+ }
if ( settings & OContactAccess::DateDiff ) {
@@ -311,3 +316,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
// will take this date instead of
- // the current one..
+ // the current one..
if ( !d.date().isValid() )
@@ -319,8 +324,8 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
// the search will fail..
- checkDate->setYMD( current.year(),
- checkDate->month(),
+ checkDate->setYMD( current.year(),
+ checkDate->month(),
checkDate->day() );
if ( *checkDate < current )
- checkDate->setYMD( current.year()+1,
- checkDate->month(),
+ checkDate->setYMD( current.year()+1,
+ checkDate->month(),
checkDate->day() );
@@ -330,8 +335,8 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
// ( maximum time range ) !
- qWarning("Checking if %s is between %s and %s ! ",
+ qWarning("Checking if %s is between %s and %s ! ",
checkDate->toString().latin1(),
- current.toString().latin1(),
+ current.toString().latin1(),
queryDate->toString().latin1() );
if ( current.daysTo( *queryDate ) >= 0 ){
- if ( !( ( *checkDate >= current ) &&
+ if ( !( ( *checkDate >= current ) &&
( *checkDate <= *queryDate ) ) ){
@@ -347,3 +352,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
}
-
+
delete queryDate;
@@ -361,5 +366,5 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
| OContactAccess::DateDay
- | OContactAccess::MatchOne
+ | OContactAccess::MatchOne
) ){
-
+
case OContactAccess::RegExp:{
@@ -399,6 +404,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
}
-
+
// Shrink to fit..
m_currentQuery.resize(arraycounter);
-
+
return m_currentQuery;
@@ -411,3 +416,3 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
uint arraycounter = 0;
-
+
for( ; it.current(); ++it ){
@@ -416,3 +421,3 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
}
-
+
}
@@ -420,3 +425,3 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
m_currentQuery.resize(arraycounter);
-
+
return m_currentQuery;
@@ -429,3 +434,3 @@ const uint OContactAccessBackend_XML::querySettings()
| OContactAccess::RegExp
- | OContactAccess::ExactMatch
+ | OContactAccess::ExactMatch
| OContactAccess::DateDiff
@@ -439,3 +444,3 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
{
- /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
+ /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
* may be added with any of the other settings. IgnoreCase should never used alone.
@@ -443,6 +448,6 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
*/
-
- if ( querySettings == OContactAccess::IgnoreCase )
+
+ if ( querySettings == OContactAccess::IgnoreCase )
return false;
-
+
switch ( querySettings & ~( OContactAccess::IgnoreCase
@@ -452,3 +457,3 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
| OContactAccess::DateDay
- )
+ )
){
@@ -465,4 +470,4 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
-// Currently only asc implemented..
-QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
+// Currently only asc implemented..
+QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
{
@@ -471,4 +476,4 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
QArray<int> m_currentQuery( m_contactList.count() );
-
- // First fill map and StringList with all Names
+
+ // First fill map and StringList with all Names
// Afterwards sort namelist and use map to fill array to return..
@@ -480,3 +485,3 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
names.sort();
-
+
int i = 0;
@@ -489,5 +494,5 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
}
-
+
return m_currentQuery;
-
+
}
@@ -499,5 +504,5 @@ bool OContactAccessBackend_XML::add ( const OContact &newcontact )
addContact_p( newcontact );
-
+
m_changed = true;
-
+
return true;
@@ -508,3 +513,3 @@ bool OContactAccessBackend_XML::replace ( const OContact &contact )
m_changed = true;
-
+
OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
@@ -530,3 +535,3 @@ bool OContactAccessBackend_XML::remove ( int uid )
m_changed = true;
-
+
OContact* found = m_uidToContact.find ( QString().setNum( uid ) );
@@ -557,5 +562,5 @@ void OContactAccessBackend_XML::addContact_p( const OContact &newcontact )
/* This function loads the xml-database and the journalfile */
-bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
+bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
{
-
+
/* We use the time of the last read to check if the file was
@@ -567,6 +572,6 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
}
-
+
const int JOURNALACTION = Qtopia::Notes + 1;
const int JOURNALROW = JOURNALACTION + 1;
-
+
bool foundAction = false;
@@ -578,3 +583,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
QAsciiDict<int> dict( 47 );
-
+
dict.setAutoDelete( TRUE );
@@ -625,5 +630,5 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
dict.insert( "actionrow", new int(JOURNALROW) );
-
+
//qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() );
-
+
XMLElement *root = XMLElement::load( filename );
@@ -636,3 +641,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
element = element->firstChild();
-
+
/* Search Tag "Contacts" which is the parent of all Contacts */
@@ -663,3 +668,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
foundAction = false;
-
+
XMLElement::AttributeMap aMap = element->attributes();
@@ -670,3 +675,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
// qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
-
+
int *find = dict[ it.key() ];
@@ -679,3 +684,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
}
-
+
/* Check if special conversion is needed and add attribute
@@ -707,3 +712,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
OContact contact( contactMap );
-
+
for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
@@ -711,3 +716,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
}
-
+
if (foundAction){
@@ -736,3 +741,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
}
-
+
/* Move to next element */
@@ -750,3 +755,3 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
void OContactAccessBackend_XML::updateJournal( const OContact& cnt,
- journal_action action )
+ journal_action action )
{
@@ -756,6 +761,6 @@ void OContactAccessBackend_XML::updateJournal( const OContact& cnt,
return;
-
+
QString buf;
QCString str;
-
+
// if the file was created, we have to set the Tag "<CONTACTS>" to
@@ -768,3 +773,3 @@ void OContactAccessBackend_XML::updateJournal( const OContact& cnt,
}
-
+
buf = "<Contact ";