summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.h4
-rw-r--r--libopie/pim/ocontactaccess.cpp8
-rw-r--r--libopie/pim/ocontactaccess.h8
-rw-r--r--libopie/pim/ocontactaccessbackend.h7
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h20
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h7
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h20
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp8
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h8
-rw-r--r--libopie2/opiepim/ocontact.h4
10 files changed, 86 insertions, 8 deletions
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h
index 382ab94..038a59f 100644
--- a/libopie/pim/ocontact.h
+++ b/libopie/pim/ocontact.h
@@ -86,53 +86,49 @@ public:
void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
// personal
void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
void setBirthday( const QDate &v );
void setAnniversary( const QDate &v );
void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
void setChildren( const QString &v );
// other
void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
bool match( const QString &regexp ) const;
-
-// DON'T ATTEMPT TO USE THIS
-#ifdef QTOPIA_INTERNAL_CONTACT_MRE
bool match( const QRegExp &regexp ) const;
-#endif
// // custom
// void setCustomField( const QString &key, const QString &v )
// { replace(Custom- + key, v ); }
// name
QString fullName() const;
QString title() const { return find( Qtopia::Title ); }
QString firstName() const { return find( Qtopia::FirstName ); }
QString middleName() const { return find( Qtopia::MiddleName ); }
QString lastName() const { return find( Qtopia::LastName ); }
QString suffix() const { return find( Qtopia::Suffix ); }
QString fileAs() const { return find( Qtopia::FileAs ); }
// email
QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
QStringList emailList() const;
// home
QString homeStreet() const { return find( Qtopia::HomeStreet ); }
QString homeCity() const { return find( Qtopia::HomeCity ); }
QString homeState() const { return find( Qtopia::HomeState ); }
QString homeZip() const { return find( Qtopia::HomeZip ); }
QString homeCountry() const { return find( Qtopia::HomeCountry ); }
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp
index 2ca0283..f868b53 100644
--- a/libopie/pim/ocontactaccess.cpp
+++ b/libopie/pim/ocontactaccess.cpp
@@ -1,47 +1,50 @@
/*
* Class to manage the Contacts.
*
* 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.
* =====================================================================
* Info: This class could just work with a change in the header-file
* of the Contact class ! Therefore our libopie only compiles
* with our version of libqpe
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.6 2002/11/01 15:10:42 eilers
+ * Added regExp-search in database for all fields in a contact.
+ *
* 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
*
* Revision 1.2 2002/10/02 16:18:11 eilers
* debugged and seems to work almost perfectly ..
*
* 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 !
*
*
*/
#include "ocontactaccess.h"
#include "obackendfactory.h"
@@ -99,48 +102,53 @@ OContactAccess::~OContactAccess ()
save();
// delete m_backEnd; is done by template..
}
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 ( OPimAccessTemplate<OContact>::wasChangedExternally() )
reload();
bool status = OPimAccessTemplate<OContact>::save();
if ( !status ) return false;
/* Now tell everyone that new data is available.
*/
QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
return true;
}
+ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{
+ QArray<int> matchingContacts = m_backEnd -> matchRegexp( r );
+ return ( ORecordList<OContact>(matchingContacts, this) );
+}
+
const uint OContactAccess::querySettings()
{
return ( m_backEnd->querySettings() );
}
bool OContactAccess::hasQuerySettings ( int querySettings ) const
{
return ( m_backEnd->hasQuerySettings ( querySettings ) );
}
bool OContactAccess::wasChangedExternally()const
{
return ( m_backEnd->wasChangedExternally() );
}
void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
{
if ( msg == "addressbookUpdated()" ){
qWarning ("OContactAccess: Received addressbokUpdated()");
emit signalChanged ( this );
} else if ( msg == "flush()" ) {
qWarning ("OContactAccess: Received flush()");
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h
index da9c942..b4921d5 100644
--- a/libopie/pim/ocontactaccess.h
+++ b/libopie/pim/ocontactaccess.h
@@ -1,109 +1,117 @@
/*
* Class to manage the Contacts.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
* Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
*
* =====================================================================
* 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: Define enum for query settings
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.4 2002/11/01 15:10:42 eilers
+ * Added regExp-search in database for all fields in a contact.
+ *
* 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 !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
* =====================================================================
*/
#ifndef _OCONTACTACCESS_H
#define _OCONTACTACCESS_H
#include <qobject.h>
#include <qpe/qcopenvelope_qws.h>
#include <qvaluelist.h>
#include <qfileinfo.h>
#include "ocontact.h"
#include "ocontactaccessbackend.h"
#include "opimaccesstemplate.h"
/** Class to access the contacts database.
* This is just a frontend for the real database handling which is
* done by the backend.
+ * @see OPimAccessTemplate
*/
class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
{
Q_OBJECT
public:
/** Create Database with contacts (addressbook).
* @param appname Name of application which wants access to the database
* (i.e. "todolist")
* @param filename The name of the database file. If not set, the default one
* is used.
* @param backend Pointer to an alternative Backend. If not set, we will use
* the default backend.
* @param handlesync If <b>true</b> the database stores the current state
* automatically if it receives the signals <i>flush()</i> and <i>reload()</i>
* which are used before and after synchronisation. If the application wants
* to react itself, it should be disabled by setting it to <b>false</b>
* @see OContactAccessBackend
*/
OContactAccess (const QString appname, const QString filename = 0l,
OContactAccessBackend* backend = 0l, bool handlesync = true);
~OContactAccess ();
/** Constants for query.
* Use this constants to set the query parameters.
* Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
* @see queryByExample()
*/
enum QuerySettings {
WildCards = 0x0001,
IgnoreCase = 0x0002,
RegExp = 0x0004,
ExactMatch = 0x0008,
+ MatchOne = 0x0010 // Only one Entry must match
};
+
+ ORecordList<OContact> matchRegexp( const QRegExp &r )const;
+
/** Return all possible settings.
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
*/
const uint querySettings();
/** Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
bool hasQuerySettings ( int querySettings ) const;
/**
* if the resource was changed externally.
* You should use the signal instead of polling possible changes !
*/
bool wasChangedExternally()const;
/** Save contacts database.
* Save is more a "commit". After calling this function, all changes are public available.
* @return true if successful
*/
bool save();
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h
index a651477..c898f61 100644
--- a/libopie/pim/ocontactaccessbackend.h
+++ b/libopie/pim/ocontactaccessbackend.h
@@ -1,74 +1,81 @@
/**
* The class responsible for managing a backend.
* The implementation of this abstract class contains
* the complete database handling.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
* Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
*
* =====================================================================
* 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: Define enum for query settings
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.3 2002/11/01 15:10:42 eilers
+ * Added regExp-search in database for all fields in a contact.
+ *
* 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_H_
#define _OCONTACTACCESSBACKEND_H_
#include "ocontact.h"
#include "opimaccessbackend.h"
+#include "qregexp.h"
+
class OContactAccessBackend: public OPimAccessBackend<OContact> {
public:
OContactAccessBackend() {}
virtual ~OContactAccessBackend() {}
/** Return if database was changed externally.
* This may just make sense on file based databases like a XML-File.
* It is used to prevent to overwrite the current database content
* if the file was already changed by something else !
* If this happens, we have to reload before save our data.
* If we use real databases, this should be handled by the database
* management system themselve, therefore this function should always return false in
* this case. It is not our problem to handle this conflict ...
* @return <i>true</i> if the database was changed and if save without reload will
* be dangerous. <i>false</i> if the database was not changed or it is save to write
* in this situation.
*/
virtual bool wasChangedExternally() = 0;
+ virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0;
+
/** Return all possible settings.
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
*/
virtual const uint querySettings() = 0;
/** Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
virtual bool hasQuerySettings (uint querySettings) const = 0;
};
#endif
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index 12a75ba..f7e8207 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,43 +1,46 @@
/*
* 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.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>
@@ -233,48 +236,65 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
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 );
}
bool hasQuerySettings (uint querySettings) const
{
/* OContactAccess::IgnoreCase may be added with one
* of the other settings, but never used alone.
* The other settings are just valid alone...
*/
switch ( querySettings & ~OContactAccess::IgnoreCase ){
case OContactAccess::RegExp:
return ( true );
case OContactAccess::WildCards:
return ( true );
case OContactAccess::ExactMatch:
return ( true );
default:
return ( false );
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index a651477..c898f61 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -1,74 +1,81 @@
/**
* The class responsible for managing a backend.
* The implementation of this abstract class contains
* the complete database handling.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
* Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
*
* =====================================================================
* 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: Define enum for query settings
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.3 2002/11/01 15:10:42 eilers
+ * Added regExp-search in database for all fields in a contact.
+ *
* 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_H_
#define _OCONTACTACCESSBACKEND_H_
#include "ocontact.h"
#include "opimaccessbackend.h"
+#include "qregexp.h"
+
class OContactAccessBackend: public OPimAccessBackend<OContact> {
public:
OContactAccessBackend() {}
virtual ~OContactAccessBackend() {}
/** Return if database was changed externally.
* This may just make sense on file based databases like a XML-File.
* It is used to prevent to overwrite the current database content
* if the file was already changed by something else !
* If this happens, we have to reload before save our data.
* If we use real databases, this should be handled by the database
* management system themselve, therefore this function should always return false in
* this case. It is not our problem to handle this conflict ...
* @return <i>true</i> if the database was changed and if save without reload will
* be dangerous. <i>false</i> if the database was not changed or it is save to write
* in this situation.
*/
virtual bool wasChangedExternally() = 0;
+ virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0;
+
/** Return all possible settings.
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
*/
virtual const uint querySettings() = 0;
/** Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
virtual bool hasQuerySettings (uint querySettings) const = 0;
};
#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index 12a75ba..f7e8207 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -1,43 +1,46 @@
/*
* 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.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>
@@ -233,48 +236,65 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
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 );
}
bool hasQuerySettings (uint querySettings) const
{
/* OContactAccess::IgnoreCase may be added with one
* of the other settings, but never used alone.
* The other settings are just valid alone...
*/
switch ( querySettings & ~OContactAccess::IgnoreCase ){
case OContactAccess::RegExp:
return ( true );
case OContactAccess::WildCards:
return ( true );
case OContactAccess::ExactMatch:
return ( true );
default:
return ( false );
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 2ca0283..f868b53 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,47 +1,50 @@
/*
* Class to manage the Contacts.
*
* 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.
* =====================================================================
* Info: This class could just work with a change in the header-file
* of the Contact class ! Therefore our libopie only compiles
* with our version of libqpe
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.6 2002/11/01 15:10:42 eilers
+ * Added regExp-search in database for all fields in a contact.
+ *
* 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
*
* Revision 1.2 2002/10/02 16:18:11 eilers
* debugged and seems to work almost perfectly ..
*
* 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 !
*
*
*/
#include "ocontactaccess.h"
#include "obackendfactory.h"
@@ -99,48 +102,53 @@ OContactAccess::~OContactAccess ()
save();
// delete m_backEnd; is done by template..
}
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 ( OPimAccessTemplate<OContact>::wasChangedExternally() )
reload();
bool status = OPimAccessTemplate<OContact>::save();
if ( !status ) return false;
/* Now tell everyone that new data is available.
*/
QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
return true;
}
+ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{
+ QArray<int> matchingContacts = m_backEnd -> matchRegexp( r );
+ return ( ORecordList<OContact>(matchingContacts, this) );
+}
+
const uint OContactAccess::querySettings()
{
return ( m_backEnd->querySettings() );
}
bool OContactAccess::hasQuerySettings ( int querySettings ) const
{
return ( m_backEnd->hasQuerySettings ( querySettings ) );
}
bool OContactAccess::wasChangedExternally()const
{
return ( m_backEnd->wasChangedExternally() );
}
void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
{
if ( msg == "addressbookUpdated()" ){
qWarning ("OContactAccess: Received addressbokUpdated()");
emit signalChanged ( this );
} else if ( msg == "flush()" ) {
qWarning ("OContactAccess: Received flush()");
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index da9c942..b4921d5 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -1,109 +1,117 @@
/*
* Class to manage the Contacts.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
* Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
*
* =====================================================================
* 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: Define enum for query settings
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.4 2002/11/01 15:10:42 eilers
+ * Added regExp-search in database for all fields in a contact.
+ *
* 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 !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
* =====================================================================
*/
#ifndef _OCONTACTACCESS_H
#define _OCONTACTACCESS_H
#include <qobject.h>
#include <qpe/qcopenvelope_qws.h>
#include <qvaluelist.h>
#include <qfileinfo.h>
#include "ocontact.h"
#include "ocontactaccessbackend.h"
#include "opimaccesstemplate.h"
/** Class to access the contacts database.
* This is just a frontend for the real database handling which is
* done by the backend.
+ * @see OPimAccessTemplate
*/
class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
{
Q_OBJECT
public:
/** Create Database with contacts (addressbook).
* @param appname Name of application which wants access to the database
* (i.e. "todolist")
* @param filename The name of the database file. If not set, the default one
* is used.
* @param backend Pointer to an alternative Backend. If not set, we will use
* the default backend.
* @param handlesync If <b>true</b> the database stores the current state
* automatically if it receives the signals <i>flush()</i> and <i>reload()</i>
* which are used before and after synchronisation. If the application wants
* to react itself, it should be disabled by setting it to <b>false</b>
* @see OContactAccessBackend
*/
OContactAccess (const QString appname, const QString filename = 0l,
OContactAccessBackend* backend = 0l, bool handlesync = true);
~OContactAccess ();
/** Constants for query.
* Use this constants to set the query parameters.
* Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
* @see queryByExample()
*/
enum QuerySettings {
WildCards = 0x0001,
IgnoreCase = 0x0002,
RegExp = 0x0004,
ExactMatch = 0x0008,
+ MatchOne = 0x0010 // Only one Entry must match
};
+
+ ORecordList<OContact> matchRegexp( const QRegExp &r )const;
+
/** Return all possible settings.
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
*/
const uint querySettings();
/** Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
bool hasQuerySettings ( int querySettings ) const;
/**
* if the resource was changed externally.
* You should use the signal instead of polling possible changes !
*/
bool wasChangedExternally()const;
/** Save contacts database.
* Save is more a "commit". After calling this function, all changes are public available.
* @return true if successful
*/
bool save();
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
index 382ab94..038a59f 100644
--- a/libopie2/opiepim/ocontact.h
+++ b/libopie2/opiepim/ocontact.h
@@ -86,53 +86,49 @@ public:
void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
// personal
void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
void setBirthday( const QDate &v );
void setAnniversary( const QDate &v );
void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
void setChildren( const QString &v );
// other
void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
bool match( const QString &regexp ) const;
-
-// DON'T ATTEMPT TO USE THIS
-#ifdef QTOPIA_INTERNAL_CONTACT_MRE
bool match( const QRegExp &regexp ) const;
-#endif
// // custom
// void setCustomField( const QString &key, const QString &v )
// { replace(Custom- + key, v ); }
// name
QString fullName() const;
QString title() const { return find( Qtopia::Title ); }
QString firstName() const { return find( Qtopia::FirstName ); }
QString middleName() const { return find( Qtopia::MiddleName ); }
QString lastName() const { return find( Qtopia::LastName ); }
QString suffix() const { return find( Qtopia::Suffix ); }
QString fileAs() const { return find( Qtopia::FileAs ); }
// email
QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
QStringList emailList() const;
// home
QString homeStreet() const { return find( Qtopia::HomeStreet ); }
QString homeCity() const { return find( Qtopia::HomeCity ); }
QString homeState() const { return find( Qtopia::HomeState ); }
QString homeZip() const { return find( Qtopia::HomeZip ); }
QString homeCountry() const { return find( Qtopia::HomeCountry ); }