summaryrefslogtreecommitdiff
authoreilers <eilers>2003-01-03 16:58:03 (UTC)
committer eilers <eilers>2003-01-03 16:58:03 (UTC)
commit7a97cd36cbc4c1a82043cdd44c82f931e2cdbb7f (patch) (side-by-side diff)
tree7b5b2eb5382b3b33ddc752d0b39312f5f00c04a7
parentd265299dd3d2ed39a343d3bdfd05eda6705a5c2c (diff)
downloadopie-7a97cd36cbc4c1a82043cdd44c82f931e2cdbb7f.zip
opie-7a97cd36cbc4c1a82043cdd44c82f931e2cdbb7f.tar.gz
opie-7a97cd36cbc4c1a82043cdd44c82f931e2cdbb7f.tar.bz2
Reenable debug output
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h17
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h17
2 files changed, 22 insertions, 12 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index 6a1c91d..6477705 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,115 +1,118 @@
/*
* XML Backend for the OPIE-Contact Database.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.12 2003/01/03 16:58:03 eilers
+ * Reenable debug output
+ *
* Revision 1.11 2003/01/03 12:31:28 eilers
* Bugfix for calculating data diffs..
*
* Revision 1.10 2003/01/02 14:27:12 eilers
* Improved query by example: Search by date is possible.. First step
* for a today plugin for birthdays..
*
* Revision 1.9 2002/12/08 12:48:57 eilers
* Moved journal-enum from ocontact into i the xml-backend..
*
* Revision 1.8 2002/11/14 17:04:24 eilers
* Sorting will now work if fullname is identical on some entries
*
* Revision 1.7 2002/11/13 15:02:46 eilers
* Small Bug in sorted fixed
*
* Revision 1.6 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.5 2002/11/01 15:10:42 eilers
* Added regExp-search in database for all fields in a contact.
*
* 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
*
* 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 !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
*
*/
#ifndef _OContactAccessBackend_XML_
#define _OContactAccessBackend_XML_
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
#include <qarray.h>
#include <qmap.h>
#include <qdatetime.h>
#include <qpe/global.h>
#include <opie/xmltree.h>
#include "ocontactaccessbackend.h"
#include "ocontactaccess.h"
#include <stdlib.h>
#include <errno.h>
using namespace Opie;
/* the default xml implementation */
class OContactAccessBackend_XML : public OContactAccessBackend {
public:
OContactAccessBackend_XML ( QString appname, QString filename = 0l ):
m_changed( false )
{
m_appName = appname;
/* Set journalfile name ... */
m_journalName = getenv("HOME");
m_journalName +="/.abjournal" + appname;
/* Expecting to access the default filename if nothing else is set */
if ( filename.isEmpty() ){
m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
} else
m_fileName = filename;
/* 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;
@@ -174,206 +177,208 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
*/
load (m_journalName, true);
return true;
}
void clear () {
m_contactList.clear();
m_changed = false;
}
bool wasChangedExternally()
{
QFileInfo fi( m_fileName );
QDateTime lastmod = fi.lastModified ();
return (lastmod != m_readtime);
}
QArray<int> allRecords() const {
QArray<int> uid_list( m_contactList.count() );
uint counter = 0;
QValueListConstIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
uid_list[counter++] = (*it).uid();
}
return ( uid_list );
}
OContact 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;
}
}
if ( found ){
foundContact = *it;
}
return ( foundContact );
}
QArray<int> queryByExample ( const OContact &query, int settings ){
QArray<int> m_currentQuery( m_contactList.count() );
QValueListConstIterator<OContact> it;
uint arraycounter = 0;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
/* Search all fields and compare them with query object. Store them into list
* if all fields matches.
*/
QDate* queryDate = 0l;
QDate* checkDate = 0l;
bool allcorrect = true;
for ( int i = 0; i < Qtopia::Groups; i++ ) {
// Birthday and anniversary are special nonstring fields and should
// be handled specially
switch ( i ){
case Qtopia::Birthday:
queryDate = new QDate( query.birthday() );
checkDate = new QDate( (*it).birthday() );
case Qtopia::Anniversary:
if ( queryDate == 0l ){
queryDate = new QDate( query.anniversary() );
checkDate = new QDate( (*it).anniversary() );
}
if ( queryDate->isValid() ){
if( checkDate->isValid() ){
if ( settings & OContactAccess::DateYear ){
if ( queryDate->year() != checkDate->year() )
allcorrect = false;
}
if ( settings & OContactAccess::DateMonth ){
if ( queryDate->month() != checkDate->month() )
allcorrect = false;
}
if ( settings & OContactAccess::DateDay ){
if ( queryDate->day() != checkDate->day() )
allcorrect = false;
}
if ( settings & OContactAccess::DateDiff ) {
QDate current = QDate::currentDate();
// We have to equalize the year, otherwise
// the search will fail..
- checkDate->setYMD( current.year(), checkDate->month(), checkDate->day() );
+ checkDate->setYMD( current.year(),
+ checkDate->month(),
+ checkDate->day() );
if ( *checkDate < current )
checkDate->setYMD( current.year()+1,
checkDate->month(),
checkDate->day() );
- // qWarning("Checking if %s is between %s and %s ! ",
- // checkDate->toString().latin1(),
- // current.toString().latin1(),
- // queryDate->toString().latin1() );
+ qWarning("Checking if %s is between %s and %s ! ",
+ checkDate->toString().latin1(),
+ current.toString().latin1(),
+ queryDate->toString().latin1() );
if ( current.daysTo( *queryDate ) > 0 ){
if ( !( ( *checkDate >= current ) &&
( *checkDate <= *queryDate ) ) ){
allcorrect = false;
- //qWarning (" Nope!..");
+ qWarning (" Nope!..");
}
}
}
} else{
// checkDate is invalid. Therfore this entry is always rejected
allcorrect = false;
}
}
delete queryDate;
queryDate = 0l;
delete checkDate;
checkDate = 0l;
break;
default:
/* Just compare fields which are not empty in the query object */
if ( !query.field(i).isEmpty() ){
switch ( settings & ~( OContactAccess::IgnoreCase
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
| OContactAccess::MatchOne
) ){
case OContactAccess::RegExp:{
QRegExp expr ( query.field(i),
!(settings & OContactAccess::IgnoreCase),
false );
if ( expr.find ( (*it).field(i), 0 ) == -1 )
allcorrect = false;
}
break;
case OContactAccess::WildCards:{
QRegExp expr ( query.field(i),
!(settings & OContactAccess::IgnoreCase),
true );
if ( expr.find ( (*it).field(i), 0 ) == -1 )
allcorrect = false;
}
break;
case OContactAccess::ExactMatch:{
if (settings & OContactAccess::IgnoreCase){
if ( query.field(i).upper() !=
(*it).field(i).upper() )
allcorrect = false;
}else{
if ( query.field(i) != (*it).field(i) )
allcorrect = false;
}
}
break;
}
}
}
}
if ( allcorrect ){
m_currentQuery[arraycounter++] = (*it).uid();
}
}
// Shrink to fit..
m_currentQuery.resize(arraycounter);
return m_currentQuery;
}
QArray<int> matchRegexp( const QRegExp &r ) const{
QArray<int> m_currentQuery( m_contactList.count() );
QValueListConstIterator<OContact> it;
uint arraycounter = 0;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ( (*it).match( r ) ){
m_currentQuery[arraycounter++] = (*it).uid();
}
}
// Shrink to fit..
m_currentQuery.resize(arraycounter);
return m_currentQuery;
}
const uint querySettings()
{
return ( OContactAccess::WildCards
| OContactAccess::IgnoreCase
| OContactAccess::RegExp
| OContactAccess::ExactMatch
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
);
}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index 6a1c91d..6477705 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -1,115 +1,118 @@
/*
* XML Backend for the OPIE-Contact Database.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.12 2003/01/03 16:58:03 eilers
+ * Reenable debug output
+ *
* Revision 1.11 2003/01/03 12:31:28 eilers
* Bugfix for calculating data diffs..
*
* Revision 1.10 2003/01/02 14:27:12 eilers
* Improved query by example: Search by date is possible.. First step
* for a today plugin for birthdays..
*
* Revision 1.9 2002/12/08 12:48:57 eilers
* Moved journal-enum from ocontact into i the xml-backend..
*
* Revision 1.8 2002/11/14 17:04:24 eilers
* Sorting will now work if fullname is identical on some entries
*
* Revision 1.7 2002/11/13 15:02:46 eilers
* Small Bug in sorted fixed
*
* Revision 1.6 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.5 2002/11/01 15:10:42 eilers
* Added regExp-search in database for all fields in a contact.
*
* 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
*
* 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 !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
*
*/
#ifndef _OContactAccessBackend_XML_
#define _OContactAccessBackend_XML_
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
#include <qarray.h>
#include <qmap.h>
#include <qdatetime.h>
#include <qpe/global.h>
#include <opie/xmltree.h>
#include "ocontactaccessbackend.h"
#include "ocontactaccess.h"
#include <stdlib.h>
#include <errno.h>
using namespace Opie;
/* the default xml implementation */
class OContactAccessBackend_XML : public OContactAccessBackend {
public:
OContactAccessBackend_XML ( QString appname, QString filename = 0l ):
m_changed( false )
{
m_appName = appname;
/* Set journalfile name ... */
m_journalName = getenv("HOME");
m_journalName +="/.abjournal" + appname;
/* Expecting to access the default filename if nothing else is set */
if ( filename.isEmpty() ){
m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
} else
m_fileName = filename;
/* 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;
@@ -174,206 +177,208 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
*/
load (m_journalName, true);
return true;
}
void clear () {
m_contactList.clear();
m_changed = false;
}
bool wasChangedExternally()
{
QFileInfo fi( m_fileName );
QDateTime lastmod = fi.lastModified ();
return (lastmod != m_readtime);
}
QArray<int> allRecords() const {
QArray<int> uid_list( m_contactList.count() );
uint counter = 0;
QValueListConstIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
uid_list[counter++] = (*it).uid();
}
return ( uid_list );
}
OContact 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;
}
}
if ( found ){
foundContact = *it;
}
return ( foundContact );
}
QArray<int> queryByExample ( const OContact &query, int settings ){
QArray<int> m_currentQuery( m_contactList.count() );
QValueListConstIterator<OContact> it;
uint arraycounter = 0;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
/* Search all fields and compare them with query object. Store them into list
* if all fields matches.
*/
QDate* queryDate = 0l;
QDate* checkDate = 0l;
bool allcorrect = true;
for ( int i = 0; i < Qtopia::Groups; i++ ) {
// Birthday and anniversary are special nonstring fields and should
// be handled specially
switch ( i ){
case Qtopia::Birthday:
queryDate = new QDate( query.birthday() );
checkDate = new QDate( (*it).birthday() );
case Qtopia::Anniversary:
if ( queryDate == 0l ){
queryDate = new QDate( query.anniversary() );
checkDate = new QDate( (*it).anniversary() );
}
if ( queryDate->isValid() ){
if( checkDate->isValid() ){
if ( settings & OContactAccess::DateYear ){
if ( queryDate->year() != checkDate->year() )
allcorrect = false;
}
if ( settings & OContactAccess::DateMonth ){
if ( queryDate->month() != checkDate->month() )
allcorrect = false;
}
if ( settings & OContactAccess::DateDay ){
if ( queryDate->day() != checkDate->day() )
allcorrect = false;
}
if ( settings & OContactAccess::DateDiff ) {
QDate current = QDate::currentDate();
// We have to equalize the year, otherwise
// the search will fail..
- checkDate->setYMD( current.year(), checkDate->month(), checkDate->day() );
+ checkDate->setYMD( current.year(),
+ checkDate->month(),
+ checkDate->day() );
if ( *checkDate < current )
checkDate->setYMD( current.year()+1,
checkDate->month(),
checkDate->day() );
- // qWarning("Checking if %s is between %s and %s ! ",
- // checkDate->toString().latin1(),
- // current.toString().latin1(),
- // queryDate->toString().latin1() );
+ qWarning("Checking if %s is between %s and %s ! ",
+ checkDate->toString().latin1(),
+ current.toString().latin1(),
+ queryDate->toString().latin1() );
if ( current.daysTo( *queryDate ) > 0 ){
if ( !( ( *checkDate >= current ) &&
( *checkDate <= *queryDate ) ) ){
allcorrect = false;
- //qWarning (" Nope!..");
+ qWarning (" Nope!..");
}
}
}
} else{
// checkDate is invalid. Therfore this entry is always rejected
allcorrect = false;
}
}
delete queryDate;
queryDate = 0l;
delete checkDate;
checkDate = 0l;
break;
default:
/* Just compare fields which are not empty in the query object */
if ( !query.field(i).isEmpty() ){
switch ( settings & ~( OContactAccess::IgnoreCase
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
| OContactAccess::MatchOne
) ){
case OContactAccess::RegExp:{
QRegExp expr ( query.field(i),
!(settings & OContactAccess::IgnoreCase),
false );
if ( expr.find ( (*it).field(i), 0 ) == -1 )
allcorrect = false;
}
break;
case OContactAccess::WildCards:{
QRegExp expr ( query.field(i),
!(settings & OContactAccess::IgnoreCase),
true );
if ( expr.find ( (*it).field(i), 0 ) == -1 )
allcorrect = false;
}
break;
case OContactAccess::ExactMatch:{
if (settings & OContactAccess::IgnoreCase){
if ( query.field(i).upper() !=
(*it).field(i).upper() )
allcorrect = false;
}else{
if ( query.field(i) != (*it).field(i) )
allcorrect = false;
}
}
break;
}
}
}
}
if ( allcorrect ){
m_currentQuery[arraycounter++] = (*it).uid();
}
}
// Shrink to fit..
m_currentQuery.resize(arraycounter);
return m_currentQuery;
}
QArray<int> matchRegexp( const QRegExp &r ) const{
QArray<int> m_currentQuery( m_contactList.count() );
QValueListConstIterator<OContact> it;
uint arraycounter = 0;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ( (*it).match( r ) ){
m_currentQuery[arraycounter++] = (*it).uid();
}
}
// Shrink to fit..
m_currentQuery.resize(arraycounter);
return m_currentQuery;
}
const uint querySettings()
{
return ( OContactAccess::WildCards
| OContactAccess::IgnoreCase
| OContactAccess::RegExp
| OContactAccess::ExactMatch
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
);
}