summaryrefslogtreecommitdiff
path: root/libopie/pim/ocontactaccessbackend_xml.cpp
Side-by-side diff
Diffstat (limited to 'libopie/pim/ocontactaccessbackend_xml.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.cpp160
1 files changed, 99 insertions, 61 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp
index 2df6757..4abf4d9 100644
--- a/libopie/pim/ocontactaccessbackend_xml.cpp
+++ b/libopie/pim/ocontactaccessbackend_xml.cpp
@@ -19,2 +19,16 @@
* $Log$
+ * Revision 1.2 2003/03/21 10:33:09 eilers
+ * Merged speed optimized xml backend for contacts to main.
+ * Added QDateTime to querybyexample. For instance, it is now possible to get
+ * all Birthdays/Anniversaries between two dates. This should be used
+ * to show all birthdays in the datebook..
+ * This change is sourcecode backward compatible but you have to upgrade
+ * the binaries for today-addressbook.
+ *
+ * Revision 1.1.2.2 2003/02/11 12:17:28 eilers
+ * Speed optimization. Removed the sequential search loops.
+ *
+ * Revision 1.1.2.1 2003/02/10 15:31:38 eilers
+ * Writing offsets to debug output..
+ *
* Revision 1.1 2003/02/09 15:05:01 eilers
@@ -91,2 +105,7 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString
{
+ // Just m_contactlist should call delete if an entry
+ // is removed.
+ m_contactList.setAutoDelete( true );
+ m_uidToContact.setAutoDelete( false );
+
m_appName = appname;
@@ -119,3 +138,6 @@ bool OContactAccessBackend_XML::save()
int total_written;
+ int idx_offset = 0;
QString out;
+
+ // Write Header
out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
@@ -124,10 +146,17 @@ bool OContactAccessBackend_XML::save()
" <Contacts>\n";
- //QValueList<Contact>::iterator it;
- QValueListConstIterator<OContact> it;
- for ( it = m_contactList.begin(); it != m_contactList.end(); ++it ) {
+ QCString cstr = out.utf8();
+ f.writeBlock( cstr.data(), cstr.length() );
+ idx_offset += cstr.length();
+ out = "";
+
+ // Write all contacts
+ QListIterator<OContact> it( m_contactList );
+ for ( ; it.current(); ++it ) {
+ qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset );
out += "<Contact ";
- (*it).save( out );
+ (*it)->save( out );
out += "/>\n";
- QCString cstr = out.utf8();
+ cstr = out.utf8();
total_written = f.writeBlock( cstr.data(), cstr.length() );
+ idx_offset += cstr.length();
if ( total_written != int(cstr.length()) ) {
@@ -141,3 +170,4 @@ bool OContactAccessBackend_XML::save()
- QCString cstr = out.utf8();
+ // Write Footer
+ cstr = out.utf8();
total_written = f.writeBlock( cstr.data(), cstr.length() );
@@ -169,2 +199,3 @@ bool OContactAccessBackend_XML::load ()
m_contactList.clear();
+ m_uidToContact.clear();
@@ -187,4 +218,5 @@ void OContactAccessBackend_XML::clear ()
m_contactList.clear();
- m_changed = false;
+ m_uidToContact.clear();
+ m_changed = false;
}
@@ -205,5 +237,5 @@ QArray<int> OContactAccessBackend_XML::allRecords() const
uint counter = 0;
- QValueListConstIterator<OContact> it;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
- uid_list[counter++] = (*it).uid();
+ QListIterator<OContact> it( m_contactList );
+ for( ; it.current(); ++it ){
+ uid_list[counter++] = (*it)->uid();
}
@@ -215,14 +247,8 @@ OContact OContactAccessBackend_XML::find ( int uid ) const
{
- bool found = false;
OContact foundContact; //Create empty contact
- QValueListConstIterator<OContact> it;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
- if ((*it).uid() == uid){
- found = true;
- break;
- }
- }
+ OContact* found = m_uidToContact.find( QString().setNum( uid ) );
+
if ( found ){
- foundContact = *it;
+ foundContact = *found;
}
@@ -232,3 +258,4 @@ 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 )
{
@@ -236,6 +263,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
QArray<int> m_currentQuery( m_contactList.count() );
- QValueListConstIterator<OContact> it;
+ QListIterator<OContact> it( m_contactList );
uint arraycounter = 0;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
+ for( ; it.current(); ++it ){
/* Search all fields and compare them with query object. Store them into list
@@ -252,3 +279,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
queryDate = new QDate( query.birthday() );
- checkDate = new QDate( (*it).birthday() );
+ checkDate = new QDate( (*it)->birthday() );
case Qtopia::Anniversary:
@@ -256,3 +283,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
queryDate = new QDate( query.anniversary() );
- checkDate = new QDate( (*it).anniversary() );
+ checkDate = new QDate( (*it)->anniversary() );
}
@@ -274,3 +301,11 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
if ( settings & OContactAccess::DateDiff ) {
- QDate current = QDate::currentDate();
+ QDate current;
+ // If we get an additional date, we
+ // will take this date instead of
+ // the current one..
+ if ( !d.date().isValid() )
+ current = QDate::currentDate();
+ else
+ current = d.date();
+
// We have to equalize the year, otherwise
@@ -284,2 +319,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
checkDate->day() );
+
+ // Check whether the birthday/anniversary date is between
+ // the current/given date and the maximum date
+ // ( maximum time range ) !
qWarning("Checking if %s is between %s and %s ! ",
@@ -297,3 +336,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
} else{
- // checkDate is invalid. Therfore this entry is always rejected
+ // checkDate is invalid. Therefore this entry is always rejected
allcorrect = false;
@@ -322,3 +361,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
false );
- if ( expr.find ( (*it).field(i), 0 ) == -1 )
+ if ( expr.find ( (*it)->field(i), 0 ) == -1 )
allcorrect = false;
@@ -330,3 +369,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
true );
- if ( expr.find ( (*it).field(i), 0 ) == -1 )
+ if ( expr.find ( (*it)->field(i), 0 ) == -1 )
allcorrect = false;
@@ -337,6 +376,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
if ( query.field(i).upper() !=
- (*it).field(i).upper() )
+ (*it)->field(i).upper() )
allcorrect = false;
}else{
- if ( query.field(i) != (*it).field(i) )
+ if ( query.field(i) != (*it)->field(i) )
allcorrect = false;
@@ -350,3 +389,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
if ( allcorrect ){
- m_currentQuery[arraycounter++] = (*it).uid();
+ m_currentQuery[arraycounter++] = (*it)->uid();
}
@@ -363,8 +402,8 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
QArray<int> m_currentQuery( m_contactList.count() );
- QValueListConstIterator<OContact> it;
+ QListIterator<OContact> it( m_contactList );
uint arraycounter = 0;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
- if ( (*it).match( r ) ){
- m_currentQuery[arraycounter++] = (*it).uid();
+ for( ; it.current(); ++it ){
+ if ( (*it)->match( r ) ){
+ m_currentQuery[arraycounter++] = (*it)->uid();
}
@@ -428,6 +467,6 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
// Afterwards sort namelist and use map to fill array to return..
- QValueListConstIterator<OContact> it;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
- names.append( (*it).fileAs() + QString::number( (*it).uid() ) );
- nameToUid.insert( (*it).fileAs() + QString::number( (*it).uid() ), (*it).uid() );
+ QListIterator<OContact> it( m_contactList );
+ for( ; it.current(); ++it ){
+ names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
+ nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
}
@@ -463,15 +502,15 @@ bool OContactAccessBackend_XML::replace ( const OContact &contact )
- bool found = false;
+ OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
- QValueListIterator<OContact> it;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
- if ( (*it).uid() == contact.uid() ){
- found = true;
- break;
- }
- }
if (found) {
- updateJournal (contact, ACTION_REPLACE);
- m_contactList.remove (it);
- m_contactList.append (contact);
+ OContact* newCont = new OContact( contact );
+
+ updateJournal ( *newCont, ACTION_REPLACE);
+ m_contactList.removeRef ( found );
+ m_contactList.append ( newCont );
+ m_uidToContact.remove( QString().setNum( contact.uid() ) );
+ m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
+
+ qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid());
+
return true;
@@ -485,13 +524,9 @@ bool OContactAccessBackend_XML::remove ( int uid )
- bool found = false;
- QValueListIterator<OContact> it;
- for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
- if ((*it).uid() == uid){
- found = true;
- break;
- }
- }
+ OContact* found = m_uidToContact.find ( QString().setNum( uid ) );
+
if (found) {
- updateJournal ( *it, ACTION_REMOVE);
- m_contactList.remove (it);
+ updateJournal ( *found, ACTION_REMOVE);
+ m_contactList.removeRef ( found );
+ m_uidToContact.remove( QString().setNum( uid ) );
+
return true;
@@ -508,3 +543,6 @@ void OContactAccessBackend_XML::addContact_p( const OContact &newcontact )
{
- m_contactList.append (newcontact);
+ OContact* contRef = new OContact( newcontact );
+
+ m_contactList.append ( contRef );
+ m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
}