summaryrefslogtreecommitdiff
authorzecke <zecke>2003-04-13 18:07:10 (UTC)
committer zecke <zecke>2003-04-13 18:07:10 (UTC)
commit6f610544d3db6198c90105b70fab1cc84f5a1fbd (patch) (side-by-side diff)
tree964d18f0a4cca7383a31810aa922876751c4a22c
parent0b311079ff19798866291034663757103c6ba935 (diff)
downloadopie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.zip
opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.tar.gz
opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.tar.bz2
More API doc
QString -> const QString& QString = 0l -> QString::null
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/obackendfactory.h26
-rw-r--r--libopie/pim/ocontact.h11
-rw-r--r--libopie/pim/ocontactaccess.h16
-rw-r--r--libopie/pim/ocontactaccessbackend.h32
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.cpp7
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.h18
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.cpp171
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h46
-rw-r--r--libopie/pim/odatebookaccess.cpp28
-rw-r--r--libopie/pim/odatebookaccess.h15
-rw-r--r--libopie/pim/odatebookaccessbackend.h45
-rw-r--r--libopie/pim/odatebookaccessbackend_xml.h6
-rw-r--r--libopie/pim/oevent.h17
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h26
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h32
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp7
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.h18
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp171
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h46
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h45
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.h6
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h16
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp28
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h15
-rw-r--r--libopie2/opiepim/ocontact.h11
-rw-r--r--libopie2/opiepim/oevent.h17
26 files changed, 630 insertions, 246 deletions
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h
index 3a73210..ad6cf5a 100644
--- a/libopie/pim/obackendfactory.h
+++ b/libopie/pim/obackendfactory.h
@@ -1,126 +1,150 @@
/*
* Class to manage Backends.
*
* 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: Use plugins
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.6 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.5 2003/02/21 23:31:52 zecke
* Add XML datebookresource
* -clean up todoaccessxml header
* -implement some more stuff in the oeven tester
* -extend DefaultFactory to not crash and to use datebook
*
* -reading of OEvents is working nicely.. saving will be added
* tomorrow
* -fix spelling in ODateBookAcces
*
* Revision 1.4 2002/10/14 15:55:18 eilers
* Redeactivate SQL.. ;)
*
* Revision 1.3 2002/10/10 17:08:58 zecke
* The Cache is finally in place
* I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;)
* The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster....
* I still have to fully implement read ahead
* This change is bic but sc
*
* Revision 1.2 2002/10/08 09:27:36 eilers
* Fixed libopie.pro to include the new pim-API.
* The SQL-Stuff is currently deactivated. Otherwise everyone who wants to
* compile itself would need to install libsqlite, libopiesql...
* Therefore, the backend currently uses XML only..
*
* Revision 1.1 2002/10/07 17:35:01 eilers
* added OBackendFactory for advanced backend access
*
*
* =====================================================================
*/
#ifndef OPIE_BACKENDFACTORY_H_
#define OPIE_BACKENDFACTORY_H_
#include <qstring.h>
#include <qasciidict.h>
#include <qpe/config.h>
#include "otodoaccessxml.h"
#include "ocontactaccessbackend_xml.h"
#include "odatebookaccessbackend_xml.h"
#ifdef __USE_SQL
#include "otodoaccesssql.h"
#endif
-
+/**
+ * This class is our factory. It will give us the default implementations
+ * of at least Todolist, Contacts and Datebook. In the future this class will
+ * allow users to switch the backend with ( XML->SQLite ) without the need
+ * to recompile.#
+ * This class as the whole PIM Api is making use of templates
+ *
+ * <pre>
+ * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null );
+ * backend->load();
+ * </pre>
+ *
+ * @author Stefan Eilers
+ * @version 0.1
+ */
template<class T>
class OBackendFactory
{
public:
OBackendFactory() {};
enum BACKENDS {
TODO,
CONTACT,
DATE
};
+ /**
+ * Returns a backend implementation for backendName
+ * @param backendName the type of the backend
+ * @param appName will be passed on to the backend
+ */
static T* Default( const QString backendName, const QString& appName ){
// __asm__("int3");
Config config( "pimaccess" );
config.setGroup ( backendName );
QString backend = config.readEntry( "usebackend" );
QAsciiDict<int> dict ( 3 );
dict.setAutoDelete ( TRUE );
dict.insert( "todo", new int (TODO) );
dict.insert( "contact", new int (CONTACT) );
dict.insert( "datebook", new int(DATE) );
qWarning ("TODO is: %d", TODO);
qWarning ("CONTACT is: %d", CONTACT);
int *find = dict[ backendName ];
if (!find ) return 0;
switch ( *find ){
case TODO:
#ifdef __USE_SQL
if ( backend == "sql" )
return (T*) new OTodoAccessBackendSQL("");
#else
if ( backend == "sql" )
qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
#endif
return (T*) new OTodoAccessXML( appName );
case CONTACT:
if ( backend == "sql" )
qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
return (T*) new OContactAccessBackend_XML( appName );
case DATE:
if ( backend == "sql" )
qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!");
return (T*) new ODateBookAccessBackend_XML( appName );
default:
return NULL;
}
}
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h
index 1fd1c75..25fa0e7 100644
--- a/libopie/pim/ocontact.h
+++ b/libopie/pim/ocontact.h
@@ -1,86 +1,93 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __OCONTACT_H__
#define __OCONTACT_H__
#include <opie/opimrecord.h>
#include <qpe/recordfields.h>
#include <qdatetime.h>
#include <qstringlist.h>
#if defined(QPC_TEMPLATEDLL)
// MOC_SKIP_BEGIN
QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
// MOC_SKIP_END
#endif
-class ContactPrivate;
-
+class ContactPrivate;
+
+/**
+ * OContact class represents a specialised PIM Record for contacts.
+ * It does store all kind of persopn related information.
+ *
+ * @short Contact Container
+ * @author TT, Stefan Eiler, Holger Freyther
+ */
class QPC_EXPORT OContact : public OPimRecord
{
friend class DataSet;
public:
OContact();
OContact( const QMap<int, QString> &fromMap );
virtual ~OContact();
/*
* do we need to inline them
* if yes do we need to inline them this way?
* -zecke
*/
void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
void setFileAs();
// default email address
void setDefaultEmail( const QString &v );
// inserts email to list and ensure's doesn't already exist
void insertEmail( const QString &v );
void removeEmail( const QString &v );
void clearEmails();
void insertEmails( const QStringList &v );
// home
void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
// business
void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h
index 32b2dcb..d7ceaf2 100644
--- a/libopie/pim/ocontactaccess.h
+++ b/libopie/pim/ocontactaccess.h
@@ -1,150 +1,160 @@
/*
* 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.7 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.6 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.5 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* 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.
+/**
+ * Class to access the contacts database.
* This is just a frontend for the real database handling which is
* done by the backend.
+ * This class is used to access the Contacts on a system. This class as any OPIE PIM
+ * class is backend independent.
+
* @see OPimAccessTemplate
*/
class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
{
Q_OBJECT
public:
- /** Create Database with contacts (addressbook).
+ /**
+ * 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
DateDiff = 0x0020, // Find all entries from today until given date
DateYear = 0x0040, // The year matches
DateMonth = 0x0080, // The month matches
DateDay = 0x0100, // The day matches
};
-
+
ORecordList<OContact> matchRegexp( const QRegExp &r )const;
/** Return all Contacts in a sorted manner.
* @param ascending true: Sorted in acending order.
* @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess
* @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess
* @param cat Currently not implemented. Just defined to stay compatible to otodoaccess
*/
List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) 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();
signals:
/* Signal is emitted if the database was changed. Therefore
* we may need to reload to stay consistent.
* @param which Pointer to the database who created this event. This pointer
* is useful if an application has to handle multiple databases at the same time.
* @see reload()
*/
void signalChanged ( const OContactAccess *which );
private:
// class OContactAccessPrivate;
// OContactAccessPrivate* d;
OContactAccessBackend *m_backEnd;
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h
index 821f5bf..ebeb42d 100644
--- a/libopie/pim/ocontactaccessbackend.h
+++ b/libopie/pim/ocontactaccessbackend.h
@@ -1,85 +1,107 @@
/**
* 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.5 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.4 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* 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"
+#include <qregexp.h>
+/**
+ * This class represents the interface of all Contact Backends.
+ * Derivates of this class will be used to access the contacts.
+ * As implementation currently XML and vCard exist. This class needs to be implemented
+ * if you want to provide your own storage.
+ * In all queries a list of uids is passed on instead of loading the actual record!
+ *
+ * @see OContactAccessBackend_VCard
+ * @see OContactAccessBackend_XML
+ */
class OContactAccessBackend: public OPimAccessBackend<OContact> {
public:
OContactAccessBackend() {}
virtual ~OContactAccessBackend() {}
- /** Return if database was changed externally.
+ /**
+ * 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 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.
+ /**
+ * Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
virtual bool hasQuerySettings (uint querySettings) const = 0;
- virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
+ /**
+ * FIXME!!!
+ * Returns a sorted list of records either ascendinf or descending for a giving criteria and category
+ */
+ virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
};
#endif
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp
index f24523f..270bef3 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.cpp
+++ b/libopie/pim/ocontactaccessbackend_vcard.cpp
@@ -1,127 +1,132 @@
/*
* VCard Backend for the OPIE-Contact Database.
*
* Copyright (C) 2000 Trolltech AS. All rights reserved.
* 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:
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.10 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.9 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.8 2003/02/21 16:52:49 zecke
* -Remove old Todo classes they're deprecated and today I already using the
* new API
* -Guard against self assignment in OTodo
* -Add test apps for OPIM
* -Opiefied Event classes
* -Added TimeZone handling and pinning of TimeZones to OEvent
* -Adjust ORecur and the widget to better timezone behaviour
*
* Revision 1.7 2003/02/16 22:25:46 zecke
* 0000276 Fix for that bug.. or better temp workaround
* A Preferred Number is HOME|VOICE
* A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test
* triggers both
* and the cell phone number overrides the other entries..
*
* as a temp I check that it's not equal to HOME|VOICE|CELL before setting the
* number
*
* The right and final fix would be to reorder the if statement to make it
* if else based and the less common thing put to the bottom
*
* OTodoAccessVcal fix the date for beaming
*
* Revision 1.6 2003/01/13 15:49:31 eilers
* Fixing crash when businesscard.vcf is missing..
*
* Revision 1.5 2002/12/07 13:26:22 eilers
* Fixing bug in storing anniversary..
*
* Revision 1.4 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.3 2002/11/11 16:41:09 kergoth
* no default arguments in implementation
*
* Revision 1.2 2002/11/10 15:41:53 eilers
* Bugfixes..
*
* Revision 1.1 2002/11/09 14:34:52 eilers
* Added VCard Backend.
*
*/
#include "ocontactaccessbackend_vcard.h"
#include "../../library/backend/vobject_p.h"
#include "../../library/backend/qfiledirect_p.h"
#include <qpe/timeconversion.h>
#include <qfile.h>
-OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ):
+OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ):
m_dirty( false ),
m_file( filename )
{
load();
}
bool OContactAccessBackend_VCard::load ()
{
m_map.clear();
m_dirty = false;
VObject* obj = 0l;
if ( QFile::exists(m_file) ){
obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
if ( !obj )
return false;
}else{
qWarning("File \"%s\" not found !", m_file.latin1() );
return false;
}
while ( obj ) {
OContact con = parseVObject( obj );
/*
* if uid is 0 assign a new one
* this at least happens on
* Nokia6210
*/
if ( con.uid() == 0 ){
con.setUid( 1 );
qWarning("assigned new uid %d",con.uid() );
}
m_map.insert( con.uid(), con );
VObject *t = obj;
obj = nextVObjectInList(obj);
cleanVObject( t );
}
return true;
}
bool OContactAccessBackend_VCard::reload()
{
return load();
diff --git a/libopie/pim/ocontactaccessbackend_vcard.h b/libopie/pim/ocontactaccessbackend_vcard.h
index 93e2da3..712d769 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.h
+++ b/libopie/pim/ocontactaccessbackend_vcard.h
@@ -1,86 +1,96 @@
/*
* VCard Backend for the OPIE-Contact Database.
*
* Copyright (C) 2000 Trolltech AS. All rights reserved.
* 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:
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.6 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.5 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.4 2002/12/07 13:26:22 eilers
* Fixing bug in storing anniversary..
*
* Revision 1.3 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.2 2002/11/10 15:41:53 eilers
* Bugfixes..
*
* Revision 1.1 2002/11/09 14:34:52 eilers
* Added VCard Backend.
*
*/
#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
#define __OCONTACTACCESSBACKEND_VCARD_H_
#include <opie/ocontact.h>
#include "ocontactaccessbackend.h"
class VObject;
+/**
+ * This is the vCard 2.1 implementation of the Contact Storage
+ * @see OContactAccessBackend_XML
+ * @see OPimAccessBackend
+ */
class OContactAccessBackend_VCard : public OContactAccessBackend {
public:
- OContactAccessBackend_VCard ( QString appname, QString filename = 0l );
+ OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null );
bool load ();
bool reload();
bool save();
void clear ();
bool add ( const OContact& newcontact );
bool remove ( int uid );
bool replace ( const OContact& contact );
-
+
OContact find ( int uid ) const;
QArray<int> allRecords() const;
QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() );
QArray<int> matchRegexp( const QRegExp &r ) const;
const uint querySettings();
bool hasQuerySettings (uint querySettings) const;
QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat );
bool wasChangedExternally();
-
+
private:
OContact parseVObject( VObject* obj );
VObject* createVObject( const OContact& c );
QString convDateToVCardDate( const QDate& c ) const;
QDate convVCardDateToDate( const QString& datestr );
VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
VObject *safeAddProp( VObject* o, const char* prop);
-
+
bool m_dirty : 1;
QString m_file;
QMap<int, OContact> m_map;
};
#endif
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
@@ -1,784 +1,789 @@
/*
* 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 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
* g++ compliance fix: default arguments belong into the declaration, but not the definition
*
* Revision 1.3 2003/03/21 12:26:28 eilers
* Fixing small bug: If we search a birthday from today to today, it returned
* every contact ..
*
* 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
* Nothing happened.. Just some cleanup before I will start..
*
* 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 !
*
*
*/
#include "ocontactaccessbackend_xml.h"
#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 <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;
-OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ):
+OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ):
m_changed( false )
{
// Just m_contactlist should call delete if an entry
// is removed.
m_contactList.setAutoDelete( true );
m_uidToContact.setAutoDelete( 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 OContactAccessBackend_XML::save()
+bool OContactAccessBackend_XML::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;
int idx_offset = 0;
QString out;
// Write Header
out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
" <Groups>\n"
" </Groups>\n"
" <Contacts>\n";
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 );
out += "/>\n";
cstr = out.utf8();
total_written = f.writeBlock( cstr.data(), cstr.length() );
idx_offset += cstr.length();
if ( total_written != int(cstr.length()) ) {
f.close();
QFile::remove( strNewFile );
return false;
}
out = "";
}
out += " </Contacts>\n</AddressBook>\n";
-
+
// Write Footer
cstr = out.utf8();
total_written = f.writeBlock( cstr.data(), cstr.length() );
if ( total_written != int( cstr.length() ) ) {
f.close();
QFile::remove( strNewFile );
return false;
}
f.close();
-
+
// move the file over, I'm just going to use the system call
// because, I don't feel like using QDir.
if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
qWarning( "problem renaming file %s to %s, errno: %d",
strNewFile.latin1(), m_journalName.latin1(), errno );
// remove the tmp file...
QFile::remove( strNewFile );
}
-
+
/* The journalfile should be removed now... */
removeJournal();
-
+
m_changed = false;
return true;
}
-bool OContactAccessBackend_XML::load ()
+bool OContactAccessBackend_XML::load ()
{
m_contactList.clear();
m_uidToContact.clear();
-
+
/* Load XML-File and journal if it exists */
if ( !load ( m_fileName, false ) )
return false;
/* The returncode of the journalfile is ignored due to the
* fact that it does not exist when this class is instantiated !
* But there may such a file exist, if the application crashed.
* Therefore we try to load it to get the changes before the #
* crash happened...
*/
load (m_journalName, true);
-
+
return true;
}
-void OContactAccessBackend_XML::clear ()
+void OContactAccessBackend_XML::clear ()
{
m_contactList.clear();
m_uidToContact.clear();
m_changed = false;
}
bool OContactAccessBackend_XML::wasChangedExternally()
{
QFileInfo fi( m_fileName );
-
+
QDateTime lastmod = fi.lastModified ();
-
+
return (lastmod != m_readtime);
}
-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 );
for( ; it.current(); ++it ){
uid_list[counter++] = (*it)->uid();
}
-
+
return ( uid_list );
}
OContact OContactAccessBackend_XML::find ( int uid ) const
{
OContact foundContact; //Create empty contact
-
+
OContact* found = m_uidToContact.find( QString().setNum( uid ) );
if ( found ){
foundContact = *found;
}
-
+
return ( foundContact );
}
-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() );
QListIterator<OContact> it( m_contactList );
uint arraycounter = 0;
-
+
for( ; it.current(); ++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;
// If we get an additional date, we
// will take this date instead of
- // the current one..
+ // the current one..
if ( !d.date().isValid() )
current = QDate::currentDate();
else
current = d.date();
// We have to equalize the year, otherwise
// 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() );
// 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 ! ",
+ 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 ) ) ){
allcorrect = false;
qWarning (" Nope!..");
}
}
}
} else{
// checkDate is invalid. Therefore 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
+ | 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> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
{
QArray<int> m_currentQuery( m_contactList.count() );
QListIterator<OContact> it( m_contactList );
uint arraycounter = 0;
-
+
for( ; it.current(); ++it ){
if ( (*it)->match( r ) ){
m_currentQuery[arraycounter++] = (*it)->uid();
}
-
+
}
// Shrink to fit..
m_currentQuery.resize(arraycounter);
-
+
return m_currentQuery;
}
const uint OContactAccessBackend_XML::querySettings()
{
return ( OContactAccess::WildCards
| OContactAccess::IgnoreCase
| OContactAccess::RegExp
- | OContactAccess::ExactMatch
+ | OContactAccess::ExactMatch
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
);
}
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.
* Wildcards, RegExp, ExactMatch should never used at the same time...
*/
-
- if ( querySettings == OContactAccess::IgnoreCase )
+
+ if ( querySettings == OContactAccess::IgnoreCase )
return false;
-
+
switch ( querySettings & ~( OContactAccess::IgnoreCase
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
- )
+ )
){
case OContactAccess::RegExp:
return ( true );
case OContactAccess::WildCards:
return ( true );
case OContactAccess::ExactMatch:
return ( true );
default:
return ( false );
}
}
-// 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 )
{
QMap<QString, int> nameToUid;
QStringList names;
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..
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() );
}
names.sort();
-
+
int i = 0;
if ( asc ){
for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
m_currentQuery[i++] = nameToUid[ (*it) ];
}else{
for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
m_currentQuery[i++] = nameToUid[ (*it) ];
}
-
+
return m_currentQuery;
-
+
}
bool OContactAccessBackend_XML::add ( const OContact &newcontact )
{
//qWarning("odefaultbackend: ACTION::ADD");
updateJournal (newcontact, ACTION_ADD);
addContact_p( newcontact );
-
+
m_changed = true;
-
+
return true;
}
bool OContactAccessBackend_XML::replace ( const OContact &contact )
{
m_changed = true;
-
+
OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
if ( found ) {
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;
} else
return false;
}
bool OContactAccessBackend_XML::remove ( int uid )
{
m_changed = true;
-
+
OContact* found = m_uidToContact.find ( QString().setNum( uid ) );
if ( found ) {
updateJournal ( *found, ACTION_REMOVE);
m_contactList.removeRef ( found );
m_uidToContact.remove( QString().setNum( uid ) );
return true;
} else
return false;
}
bool OContactAccessBackend_XML::reload(){
/* Reload is the same as load in this implementation */
return ( load() );
}
void OContactAccessBackend_XML::addContact_p( const OContact &newcontact )
{
OContact* contRef = new OContact( newcontact );
m_contactList.append ( contRef );
m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
}
/* 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
* changed externally.
*/
if ( !isJournal ){
QFileInfo fi( filename );
m_readtime = fi.lastModified ();
}
-
+
const int JOURNALACTION = Qtopia::Notes + 1;
const int JOURNALROW = JOURNALACTION + 1;
-
+
bool foundAction = false;
journal_action action = ACTION_ADD;
int journalKey = 0;
QMap<int, QString> contactMap;
QMap<QString, QString> customMap;
QMap<QString, QString>::Iterator customIt;
QAsciiDict<int> dict( 47 );
-
+
dict.setAutoDelete( TRUE );
dict.insert( "Uid", new int(Qtopia::AddressUid) );
dict.insert( "Title", new int(Qtopia::Title) );
dict.insert( "FirstName", new int(Qtopia::FirstName) );
dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
dict.insert( "LastName", new int(Qtopia::LastName) );
dict.insert( "Suffix", new int(Qtopia::Suffix) );
dict.insert( "FileAs", new int(Qtopia::FileAs) );
dict.insert( "Categories", new int(Qtopia::AddressCategory) );
dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
dict.insert( "Emails", new int(Qtopia::Emails) );
dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
dict.insert( "HomeState", new int(Qtopia::HomeState) );
dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
dict.insert( "Company", new int(Qtopia::Company) );
dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
dict.insert( "Department", new int(Qtopia::Department) );
dict.insert( "Office", new int(Qtopia::Office) );
dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
dict.insert( "Profession", new int(Qtopia::Profession) );
dict.insert( "Assistant", new int(Qtopia::Assistant) );
dict.insert( "Manager", new int(Qtopia::Manager) );
dict.insert( "Spouse", new int(Qtopia::Spouse) );
dict.insert( "Children", new int(Qtopia::Children) );
dict.insert( "Gender", new int(Qtopia::Gender) );
dict.insert( "Birthday", new int(Qtopia::Birthday) );
dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
dict.insert( "Nickname", new int(Qtopia::Nickname) );
dict.insert( "Notes", new int(Qtopia::Notes) );
dict.insert( "action", new int(JOURNALACTION) );
dict.insert( "actionrow", new int(JOURNALROW) );
-
+
//qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() );
-
+
XMLElement *root = XMLElement::load( filename );
if(root != 0l ){ // start parsing
/* Parse all XML-Elements and put the data into the
* Contact-Class
*/
XMLElement *element = root->firstChild();
//qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() );
element = element->firstChild();
-
+
/* Search Tag "Contacts" which is the parent of all Contacts */
while( element && !isJournal ){
if( element->tagName() != QString::fromLatin1("Contacts") ){
//qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
// element->tagName().latin1());
element = element->nextChild();
} else {
element = element->firstChild();
break;
}
}
/* Parse all Contacts and ignore unknown tags */
while( element ){
if( element->tagName() != QString::fromLatin1("Contact") ){
//qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s",
// element->tagName().latin1());
element = element->nextChild();
continue;
}
/* Found alement with tagname "contact", now parse and store all
* attributes contained
*/
//qWarning("OContactDefBack::load element tagName() : %s",
// element->tagName().latin1() );
QString dummy;
foundAction = false;
-
+
XMLElement::AttributeMap aMap = element->attributes();
XMLElement::AttributeMap::Iterator it;
contactMap.clear();
customMap.clear();
for( it = aMap.begin(); it != aMap.end(); ++it ){
// qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
-
+
int *find = dict[ it.key() ];
/* Unknown attributes will be stored as "Custom" elements */
if ( !find ) {
qWarning("Attribute %s not known.", it.key().latin1());
//contact.setCustomField(it.key(), it.data());
customMap.insert( it.key(), it.data() );
continue;
}
-
+
/* Check if special conversion is needed and add attribute
* into Contact class
*/
switch( *find ) {
/*
case Qtopia::AddressUid:
contact.setUid( it.data().toInt() );
break;
case Qtopia::AddressCategory:
contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
break;
*/
case JOURNALACTION:
action = journal_action(it.data().toInt());
foundAction = true;
qWarning ("ODefBack(journal)::ACTION found: %d", action);
break;
case JOURNALROW:
journalKey = it.data().toInt();
break;
default: // no conversion needed add them to the map
contactMap.insert( *find, it.data() );
break;
}
}
/* now generate the Contact contact */
OContact contact( contactMap );
-
+
for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
contact.setCustomField( customIt.key(), customIt.data() );
}
-
+
if (foundAction){
foundAction = false;
switch ( action ) {
case ACTION_ADD:
addContact_p (contact);
break;
case ACTION_REMOVE:
if ( !remove (contact.uid()) )
qWarning ("ODefBack(journal)::Unable to remove uid: %d",
contact.uid() );
break;
case ACTION_REPLACE:
if ( !replace ( contact ) )
qWarning ("ODefBack(journal)::Unable to replace uid: %d",
contact.uid() );
break;
default:
qWarning ("Unknown action: ignored !");
break;
}
}else{
/* Add contact to list */
addContact_p (contact);
}
-
+
/* Move to next element */
element = element->nextChild();
}
}else {
qWarning("ODefBack::could not load");
}
delete root;
qWarning("returning from loading" );
return true;
}
void OContactAccessBackend_XML::updateJournal( const OContact& cnt,
- journal_action action )
+ journal_action action )
{
QFile f( m_journalName );
bool created = !f.exists();
if ( !f.open(IO_WriteOnly|IO_Append) )
return;
-
+
QString buf;
QCString str;
-
+
// if the file was created, we have to set the Tag "<CONTACTS>" to
// get a XML-File which is readable by our parser.
// This is just a cheat, but better than rewrite the parser.
if ( created ){
buf = "<Contacts>";
QCString cstr = buf.utf8();
f.writeBlock( cstr.data(), cstr.length() );
}
-
+
buf = "<Contact ";
cnt.save( buf );
buf += " action=\"" + QString::number( (int)action ) + "\" ";
buf += "/>\n";
QCString cstr = buf.utf8();
f.writeBlock( cstr.data(), cstr.length() );
}
void OContactAccessBackend_XML::removeJournal()
{
QFile f ( m_journalName );
if ( f.exists() )
f.remove();
}
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index 4d6a7ef..7b5365b 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,144 +1,154 @@
/*
* 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.14 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.13 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.12.2.2 2003/02/11 12:17:28 eilers
* Speed optimization. Removed the sequential search loops.
*
* Revision 1.12.2.1 2003/02/09 15:05:01 eilers
* Nothing happened.. Just some cleanup before I will start..
*
* 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 "ocontactaccessbackend.h"
#include "ocontactaccess.h"
#include <qlist.h>
#include <qdict.h>
/* the default xml implementation */
+/**
+ * This class is the XML implementation of a Contact backend
+ * it does implement everything available for OContact.
+ * @see OPimAccessBackend for more information of available methods
+ */
class OContactAccessBackend_XML : public OContactAccessBackend {
public:
- OContactAccessBackend_XML ( QString appname, QString filename = 0l );
-
+ OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null );
+
bool save();
-
+
bool load ();
void clear ();
-
+
bool wasChangedExternally();
-
+
QArray<int> allRecords() const;
-
+
OContact find ( int uid ) const;
-
+
QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() );
QArray<int> matchRegexp( const QRegExp &r ) const;
-
+
const uint querySettings();
-
+
bool hasQuerySettings (uint querySettings) const;
-
- // Currently only asc implemented..
+
+ // Currently only asc implemented..
QArray<int> sorted( bool asc, int , int , int );
bool add ( const OContact &newcontact );
-
+
bool replace ( const OContact &contact );
-
+
bool remove ( int uid );
bool reload();
-
+
private:
enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
void addContact_p( const OContact &newcontact );
-
+
/* This function loads the xml-database and the journalfile */
bool load( const QString filename, bool isJournal );
-
-
+
+
void updateJournal( const OContact& cnt, journal_action action );
void removeJournal();
-
+
protected:
bool m_changed;
QString m_journalName;
QString m_fileName;
QString m_appName;
QList<OContact> m_contactList;
QDateTime m_readtime;
QDict<OContact> m_uidToContact;
};
#endif
diff --git a/libopie/pim/odatebookaccess.cpp b/libopie/pim/odatebookaccess.cpp
index 08e61ff..a3661a3 100644
--- a/libopie/pim/odatebookaccess.cpp
+++ b/libopie/pim/odatebookaccess.cpp
@@ -1,38 +1,66 @@
#include "obackendfactory.h"
#include "odatebookaccess.h"
+/**
+ * Simple constructor
+ * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation
+ * will be used!
+ * @param back The backend to be used or 0 for the default backend
+ * @param ac What kind of access is intended
+ */
ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
: OPimAccessTemplate<OEvent>( back )
{
if (!back )
back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null );
m_backEnd = back;
setBackEnd( m_backEnd );
}
ODateBookAccess::~ODateBookAccess() {
}
+
+/**
+ * @return all events available
+ */
ODateBookAccess::List ODateBookAccess::rawEvents()const {
QArray<int> ints = m_backEnd->rawEvents();
List lis( ints, this );
return lis;
}
+
+/**
+ * @return all repeating events
+ */
ODateBookAccess::List ODateBookAccess::rawRepeats()const {
QArray<int> ints = m_backEnd->rawRepeats();
List lis( ints, this );
return lis;
}
+
+/**
+ * @return all non repeating events
+ */
ODateBookAccess::List ODateBookAccess::nonRepeats()const {
QArray<int> ints = m_backEnd->nonRepeats();
List lis( ints, this );
return lis;
}
+
+/**
+ * @return dates in the time span between from and to
+ * @param from Include all events from...
+ * @param to Include all events to...
+ */
OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) {
return m_backEnd->effecticeEvents( from, to );
}
+/**
+ * @return all events at a given datetime
+ */
OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) {
return m_backEnd->effecticeEvents( start );
}
diff --git a/libopie/pim/odatebookaccess.h b/libopie/pim/odatebookaccess.h
index 7047039..7c7a63f 100644
--- a/libopie/pim/odatebookaccess.h
+++ b/libopie/pim/odatebookaccess.h
@@ -1,32 +1,41 @@
#ifndef OPIE_DATE_BOOK_ACCESS_H
#define OPIE_DATE_BOOK_ACCESS_H
#include "odatebookaccessbackend.h"
#include "opimaccesstemplate.h"
#include "oevent.h"
+/**
+ * This is the object orientated datebook database. It'll use OBackendFactory
+ * to query for a backend.
+ * All access to the datebook should be done via this class.
+ * Make sure to load and save the datebook this is not part of
+ * destructing and creating the object
+ *
+ * @author Holger Freyther
+ */
class ODateBookAccess : public OPimAccessTemplate<OEvent> {
public:
ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
~ODateBookAccess();
- /** return all events */
+ /* return all events */
List rawEvents()const;
- /** return repeating events */
+ /* return repeating events */
List rawRepeats()const;
- /** return non repeating events */
+ /* return non repeating events */
List nonRepeats()const;
OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to );
OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start );
private:
ODateBookAccessBackend* m_backEnd;
class Private;
Private* d;
};
#endif
diff --git a/libopie/pim/odatebookaccessbackend.h b/libopie/pim/odatebookaccessbackend.h
index eb6e8fb..86ff298 100644
--- a/libopie/pim/odatebookaccessbackend.h
+++ b/libopie/pim/odatebookaccessbackend.h
@@ -1,32 +1,73 @@
#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H
#define OPIE_DATE_BOOK_ACCESS_BACKEND_H
#include <qarray.h>
#include "opimaccessbackend.h"
#include "oevent.h"
+/**
+ * This class is the interface to the storage of Events.
+ * @see OPimAccessBackend
+ *
+ */
class ODateBookAccessBackend : public OPimAccessBackend<OEvent> {
public:
typedef int UID;
+
+ /**
+ * c'tor without parameter
+ */
ODateBookAccessBackend();
~ODateBookAccessBackend();
+ /**
+ * This method should return a list of UIDs containing
+ * all events. No filter should be applied
+ * @return list of events
+ */
virtual QArray<UID> rawEvents()const = 0;
+
+ /**
+ * This method should return a list of UIDs containing
+ * all repeating events. No filter should be applied
+ * @return list of repeating events
+ */
virtual QArray<UID> rawRepeats()const = 0;
+
+ /**
+ * This mthod should return a list of UIDs containing all non
+ * repeating events. No filter should be applied
+ * @return list of nonrepeating events
+ */
virtual QArray<UID> nonRepeats() const = 0;
/**
- * these two methods are used if you do not implement
- * effectiveEvents...
+ * If you do not want to implement the effectiveEvents methods below
+ * you need to supply it with directNonRepeats.
+ * This method can return empty lists if effectiveEvents is implememted
*/
virtual OEvent::ValueList directNonRepeats() = 0;
+
+ /**
+ * Same as above but return raw repeats!
+ */
virtual OEvent::ValueList directRawRepeats() = 0;
/* is implemented by default but you can reimplement it*/
+ /**
+ * Effective Events are special event occuring during a time frame. This method does calcualte
+ * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
+ * yourself
+ */
virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to );
+
+ /**
+ * this is an overloaded member function
+ * @see effecticeEvents
+ */
virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start );
};
#endif
diff --git a/libopie/pim/odatebookaccessbackend_xml.h b/libopie/pim/odatebookaccessbackend_xml.h
index 563c31f..7848f7c 100644
--- a/libopie/pim/odatebookaccessbackend_xml.h
+++ b/libopie/pim/odatebookaccessbackend_xml.h
@@ -1,48 +1,54 @@
#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H
#define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H
#include <qmap.h>
#include "odatebookaccessbackend.h"
+/**
+ * This is the default XML implementation for DateBoook XML storage
+ * It fully implements the interface
+ * @see ODateBookAccessBackend
+ * @see OPimAccessBackend
+ */
class ODateBookAccessBackend_XML : public ODateBookAccessBackend {
public:
ODateBookAccessBackend_XML( const QString& appName,
const QString& fileName = QString::null);
~ODateBookAccessBackend_XML();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() );
OEvent find( int uid )const;
void clear();
bool add( const OEvent& ev );
bool remove( int uid );
bool replace( const OEvent& ev );
QArray<UID> rawEvents()const;
QArray<UID> rawRepeats()const;
QArray<UID> nonRepeats()const;
OEvent::ValueList directNonRepeats();
OEvent::ValueList directRawRepeats();
private:
bool m_changed :1 ;
bool loadFile();
inline void finalizeRecord( OEvent& ev );
inline void setField( OEvent&, int field, const QString& val );
QString m_name;
QMap<int, OEvent> m_raw;
QMap<int, OEvent> m_rep;
struct Data;
Data* data;
class Private;
Private *d;
};
#endif
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h
index 585515c..57d32d0 100644
--- a/libopie/pim/oevent.h
+++ b/libopie/pim/oevent.h
@@ -1,195 +1,210 @@
// CONTAINS GPLed code of TT
#ifndef OPIE_PIM_EVENT_H
#define OPIE_PIM_EVENT_H
#include <qstring.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include "otimezone.h"
#include "opimrecord.h"
struct OCalendarHelper {
/** calculate the week number of the date */
static int week( const QDate& );
/** calculate the occurence of week days since the start of the month */
static int ocurrence( const QDate& );
// returns the dayOfWeek for the *first* day it finds (ignores
// any further days!). Returns 1 (Monday) if there isn't any day found
static int dayOfWeek( char day );
/** returns the diff of month */
static int monthDiff( const QDate& first, const QDate& second );
};
class OPimNotifyManager;
class ORecur;
+
+/**
+ * This is the container for all Events. It encapsules all
+ * available information for a single Event
+ * @short container for events.
+ */
class OEvent : public OPimRecord {
public:
typedef QValueList<OEvent> ValueList;
+ /**
+ * RecordFields contain possible attributes
+ */
enum RecordFields {
Uid = Qtopia::UID_ID,
Category = Qtopia::CATEGORY_ID,
Description,
Location,
Alarm,
Reminder,
Recurrence,
Note,
Created,
StartDate,
EndDate,
AllDay,
TimeZone
};
+ /**
+ * Start with an Empty OEvent. UID == 0 means that it is empty
+ */
OEvent(int uid = 0);
+
+ /**
+ * copy c'tor
+ */
OEvent( const OEvent& );
~OEvent();
OEvent &operator=( const OEvent& );
QString description()const;
void setDescription( const QString& description );
QString location()const;
void setLocation( const QString& loc );
bool hasNotifiers()const;
OPimNotifyManager &notifiers()const;
ORecur recurrence()const;
void setRecurrence( const ORecur& );
bool hasRecurrence()const;
QString note()const;
void setNote( const QString& note );
QDateTime createdDateTime()const;
void setCreatedDateTime( const QDateTime& dt);
/** set the date to dt. dt is the QDateTime in localtime */
void setStartDateTime( const QDateTime& );
/** returns the datetime in the local timeZone */
QDateTime startDateTime()const;
/** returns the start datetime in the current zone */
QDateTime startDateTimeInZone()const;
/** in current timezone */
void setEndDateTime( const QDateTime& );
/** in current timezone */
QDateTime endDateTime()const;
QDateTime endDateTimeInZone()const;
bool isMultipleDay()const;
bool isAllDay()const;
void setAllDay( bool isAllDay );
/* pin this event to a timezone! FIXME */
void setTimeZone( const QString& timeZone );
QString timeZone()const;
bool match( const QRegExp& )const;
/** For exception to recurrence here is a list of children... */
QArray<int> children()const;
void setChildren( const QArray<int>& );
void addChild( int uid );
void removeChild( int uid );
/** return the parent OEvent */
int parent()const;
void setParent( int uid );
/* needed reimp */
QString toRichText()const;
QString toShortText()const;
QString type()const;
QMap<int, QString> toMap()const;
QMap<QString, QString> toExtraMap()const;
QString recordField(int )const;
static int rtti();
bool loadFromStream( QDataStream& );
bool saveToStream( QDataStream& )const;
/* bool operator==( const OEvent& );
bool operator!=( const OEvent& );
bool operator<( const OEvent& );
bool operator<=( const OEvent& );
bool operator>( const OEvent& );
bool operator>=(const OEvent& );
*/
private:
inline void changeOrModify();
void deref();
struct Data;
Data* data;
class Private;
Private* priv;
};
/**
* AN Event can span through multiple days. We split up a multiday eve
*/
-
class OEffectiveEvent {
public:
typedef QValueList<OEffectiveEvent> ValueList;
enum Position { MidWay, Start, End, StartEnd };
// If we calculate the effective event of a multi-day event
// we have to figure out whether we are at the first day,
// at the end, or anywhere else ("middle"). This is important
// for the start/end times (00:00/23:59)
// MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
// day event
// Start: start time -> 23:59
// End: 00:00 -> end time
// Start | End == StartEnd: for single-day events (default)
// here we draw start time -> end time
OEffectiveEvent();
OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd );
OEffectiveEvent( const OEffectiveEvent& );
OEffectiveEvent &operator=(const OEffectiveEvent& );
~OEffectiveEvent();
void setStartTime( const QTime& );
void setEndTime( const QTime& );
void setEvent( const OEvent& );
void setDate( const QDate& );
void setEffectiveDates( const QDate& from, const QDate& to );
QString description()const;
QString location()const;
QString note()const;
OEvent event()const;
QTime startTime()const;
QTime endTime()const;
QDate date()const;
/* return the length in hours */
int length()const;
int size()const;
QDate startDate()const;
QDate endDate()const;
bool operator<( const OEffectiveEvent &e ) const;
bool operator<=( const OEffectiveEvent &e ) const;
bool operator==( const OEffectiveEvent &e ) const;
bool operator!=( const OEffectiveEvent &e ) const;
bool operator>( const OEffectiveEvent &e ) const;
bool operator>= ( const OEffectiveEvent &e ) const;
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 3a73210..ad6cf5a 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -1,126 +1,150 @@
/*
* Class to manage Backends.
*
* 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: Use plugins
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.6 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.5 2003/02/21 23:31:52 zecke
* Add XML datebookresource
* -clean up todoaccessxml header
* -implement some more stuff in the oeven tester
* -extend DefaultFactory to not crash and to use datebook
*
* -reading of OEvents is working nicely.. saving will be added
* tomorrow
* -fix spelling in ODateBookAcces
*
* Revision 1.4 2002/10/14 15:55:18 eilers
* Redeactivate SQL.. ;)
*
* Revision 1.3 2002/10/10 17:08:58 zecke
* The Cache is finally in place
* I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;)
* The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster....
* I still have to fully implement read ahead
* This change is bic but sc
*
* Revision 1.2 2002/10/08 09:27:36 eilers
* Fixed libopie.pro to include the new pim-API.
* The SQL-Stuff is currently deactivated. Otherwise everyone who wants to
* compile itself would need to install libsqlite, libopiesql...
* Therefore, the backend currently uses XML only..
*
* Revision 1.1 2002/10/07 17:35:01 eilers
* added OBackendFactory for advanced backend access
*
*
* =====================================================================
*/
#ifndef OPIE_BACKENDFACTORY_H_
#define OPIE_BACKENDFACTORY_H_
#include <qstring.h>
#include <qasciidict.h>
#include <qpe/config.h>
#include "otodoaccessxml.h"
#include "ocontactaccessbackend_xml.h"
#include "odatebookaccessbackend_xml.h"
#ifdef __USE_SQL
#include "otodoaccesssql.h"
#endif
-
+/**
+ * This class is our factory. It will give us the default implementations
+ * of at least Todolist, Contacts and Datebook. In the future this class will
+ * allow users to switch the backend with ( XML->SQLite ) without the need
+ * to recompile.#
+ * This class as the whole PIM Api is making use of templates
+ *
+ * <pre>
+ * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null );
+ * backend->load();
+ * </pre>
+ *
+ * @author Stefan Eilers
+ * @version 0.1
+ */
template<class T>
class OBackendFactory
{
public:
OBackendFactory() {};
enum BACKENDS {
TODO,
CONTACT,
DATE
};
+ /**
+ * Returns a backend implementation for backendName
+ * @param backendName the type of the backend
+ * @param appName will be passed on to the backend
+ */
static T* Default( const QString backendName, const QString& appName ){
// __asm__("int3");
Config config( "pimaccess" );
config.setGroup ( backendName );
QString backend = config.readEntry( "usebackend" );
QAsciiDict<int> dict ( 3 );
dict.setAutoDelete ( TRUE );
dict.insert( "todo", new int (TODO) );
dict.insert( "contact", new int (CONTACT) );
dict.insert( "datebook", new int(DATE) );
qWarning ("TODO is: %d", TODO);
qWarning ("CONTACT is: %d", CONTACT);
int *find = dict[ backendName ];
if (!find ) return 0;
switch ( *find ){
case TODO:
#ifdef __USE_SQL
if ( backend == "sql" )
return (T*) new OTodoAccessBackendSQL("");
#else
if ( backend == "sql" )
qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
#endif
return (T*) new OTodoAccessXML( appName );
case CONTACT:
if ( backend == "sql" )
qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
return (T*) new OContactAccessBackend_XML( appName );
case DATE:
if ( backend == "sql" )
qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!");
return (T*) new ODateBookAccessBackend_XML( appName );
default:
return NULL;
}
}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index 821f5bf..ebeb42d 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -1,85 +1,107 @@
/**
* 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.5 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.4 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* 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"
+#include <qregexp.h>
+/**
+ * This class represents the interface of all Contact Backends.
+ * Derivates of this class will be used to access the contacts.
+ * As implementation currently XML and vCard exist. This class needs to be implemented
+ * if you want to provide your own storage.
+ * In all queries a list of uids is passed on instead of loading the actual record!
+ *
+ * @see OContactAccessBackend_VCard
+ * @see OContactAccessBackend_XML
+ */
class OContactAccessBackend: public OPimAccessBackend<OContact> {
public:
OContactAccessBackend() {}
virtual ~OContactAccessBackend() {}
- /** Return if database was changed externally.
+ /**
+ * 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 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.
+ /**
+ * Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
virtual bool hasQuerySettings (uint querySettings) const = 0;
- virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
+ /**
+ * FIXME!!!
+ * Returns a sorted list of records either ascendinf or descending for a giving criteria and category
+ */
+ virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
};
#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index f24523f..270bef3 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -1,127 +1,132 @@
/*
* VCard Backend for the OPIE-Contact Database.
*
* Copyright (C) 2000 Trolltech AS. All rights reserved.
* 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:
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.10 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.9 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.8 2003/02/21 16:52:49 zecke
* -Remove old Todo classes they're deprecated and today I already using the
* new API
* -Guard against self assignment in OTodo
* -Add test apps for OPIM
* -Opiefied Event classes
* -Added TimeZone handling and pinning of TimeZones to OEvent
* -Adjust ORecur and the widget to better timezone behaviour
*
* Revision 1.7 2003/02/16 22:25:46 zecke
* 0000276 Fix for that bug.. or better temp workaround
* A Preferred Number is HOME|VOICE
* A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test
* triggers both
* and the cell phone number overrides the other entries..
*
* as a temp I check that it's not equal to HOME|VOICE|CELL before setting the
* number
*
* The right and final fix would be to reorder the if statement to make it
* if else based and the less common thing put to the bottom
*
* OTodoAccessVcal fix the date for beaming
*
* Revision 1.6 2003/01/13 15:49:31 eilers
* Fixing crash when businesscard.vcf is missing..
*
* Revision 1.5 2002/12/07 13:26:22 eilers
* Fixing bug in storing anniversary..
*
* Revision 1.4 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.3 2002/11/11 16:41:09 kergoth
* no default arguments in implementation
*
* Revision 1.2 2002/11/10 15:41:53 eilers
* Bugfixes..
*
* Revision 1.1 2002/11/09 14:34:52 eilers
* Added VCard Backend.
*
*/
#include "ocontactaccessbackend_vcard.h"
#include "../../library/backend/vobject_p.h"
#include "../../library/backend/qfiledirect_p.h"
#include <qpe/timeconversion.h>
#include <qfile.h>
-OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ):
+OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ):
m_dirty( false ),
m_file( filename )
{
load();
}
bool OContactAccessBackend_VCard::load ()
{
m_map.clear();
m_dirty = false;
VObject* obj = 0l;
if ( QFile::exists(m_file) ){
obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
if ( !obj )
return false;
}else{
qWarning("File \"%s\" not found !", m_file.latin1() );
return false;
}
while ( obj ) {
OContact con = parseVObject( obj );
/*
* if uid is 0 assign a new one
* this at least happens on
* Nokia6210
*/
if ( con.uid() == 0 ){
con.setUid( 1 );
qWarning("assigned new uid %d",con.uid() );
}
m_map.insert( con.uid(), con );
VObject *t = obj;
obj = nextVObjectInList(obj);
cleanVObject( t );
}
return true;
}
bool OContactAccessBackend_VCard::reload()
{
return load();
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
index 93e2da3..712d769 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
@@ -1,86 +1,96 @@
/*
* VCard Backend for the OPIE-Contact Database.
*
* Copyright (C) 2000 Trolltech AS. All rights reserved.
* 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:
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.6 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.5 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.4 2002/12/07 13:26:22 eilers
* Fixing bug in storing anniversary..
*
* Revision 1.3 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.2 2002/11/10 15:41:53 eilers
* Bugfixes..
*
* Revision 1.1 2002/11/09 14:34:52 eilers
* Added VCard Backend.
*
*/
#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
#define __OCONTACTACCESSBACKEND_VCARD_H_
#include <opie/ocontact.h>
#include "ocontactaccessbackend.h"
class VObject;
+/**
+ * This is the vCard 2.1 implementation of the Contact Storage
+ * @see OContactAccessBackend_XML
+ * @see OPimAccessBackend
+ */
class OContactAccessBackend_VCard : public OContactAccessBackend {
public:
- OContactAccessBackend_VCard ( QString appname, QString filename = 0l );
+ OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null );
bool load ();
bool reload();
bool save();
void clear ();
bool add ( const OContact& newcontact );
bool remove ( int uid );
bool replace ( const OContact& contact );
-
+
OContact find ( int uid ) const;
QArray<int> allRecords() const;
QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() );
QArray<int> matchRegexp( const QRegExp &r ) const;
const uint querySettings();
bool hasQuerySettings (uint querySettings) const;
QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat );
bool wasChangedExternally();
-
+
private:
OContact parseVObject( VObject* obj );
VObject* createVObject( const OContact& c );
QString convDateToVCardDate( const QDate& c ) const;
QDate convVCardDateToDate( const QString& datestr );
VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
VObject *safeAddProp( VObject* o, const char* prop);
-
+
bool m_dirty : 1;
QString m_file;
QMap<int, OContact> m_map;
};
#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index c5a7820..661cd51 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -1,784 +1,789 @@
/*
* 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 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
* g++ compliance fix: default arguments belong into the declaration, but not the definition
*
* Revision 1.3 2003/03/21 12:26:28 eilers
* Fixing small bug: If we search a birthday from today to today, it returned
* every contact ..
*
* 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
* Nothing happened.. Just some cleanup before I will start..
*
* 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 !
*
*
*/
#include "ocontactaccessbackend_xml.h"
#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 <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;
-OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ):
+OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ):
m_changed( false )
{
// Just m_contactlist should call delete if an entry
// is removed.
m_contactList.setAutoDelete( true );
m_uidToContact.setAutoDelete( 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 OContactAccessBackend_XML::save()
+bool OContactAccessBackend_XML::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;
int idx_offset = 0;
QString out;
// Write Header
out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
" <Groups>\n"
" </Groups>\n"
" <Contacts>\n";
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 );
out += "/>\n";
cstr = out.utf8();
total_written = f.writeBlock( cstr.data(), cstr.length() );
idx_offset += cstr.length();
if ( total_written != int(cstr.length()) ) {
f.close();
QFile::remove( strNewFile );
return false;
}
out = "";
}
out += " </Contacts>\n</AddressBook>\n";
-
+
// Write Footer
cstr = out.utf8();
total_written = f.writeBlock( cstr.data(), cstr.length() );
if ( total_written != int( cstr.length() ) ) {
f.close();
QFile::remove( strNewFile );
return false;
}
f.close();
-
+
// move the file over, I'm just going to use the system call
// because, I don't feel like using QDir.
if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
qWarning( "problem renaming file %s to %s, errno: %d",
strNewFile.latin1(), m_journalName.latin1(), errno );
// remove the tmp file...
QFile::remove( strNewFile );
}
-
+
/* The journalfile should be removed now... */
removeJournal();
-
+
m_changed = false;
return true;
}
-bool OContactAccessBackend_XML::load ()
+bool OContactAccessBackend_XML::load ()
{
m_contactList.clear();
m_uidToContact.clear();
-
+
/* Load XML-File and journal if it exists */
if ( !load ( m_fileName, false ) )
return false;
/* The returncode of the journalfile is ignored due to the
* fact that it does not exist when this class is instantiated !
* But there may such a file exist, if the application crashed.
* Therefore we try to load it to get the changes before the #
* crash happened...
*/
load (m_journalName, true);
-
+
return true;
}
-void OContactAccessBackend_XML::clear ()
+void OContactAccessBackend_XML::clear ()
{
m_contactList.clear();
m_uidToContact.clear();
m_changed = false;
}
bool OContactAccessBackend_XML::wasChangedExternally()
{
QFileInfo fi( m_fileName );
-
+
QDateTime lastmod = fi.lastModified ();
-
+
return (lastmod != m_readtime);
}
-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 );
for( ; it.current(); ++it ){
uid_list[counter++] = (*it)->uid();
}
-
+
return ( uid_list );
}
OContact OContactAccessBackend_XML::find ( int uid ) const
{
OContact foundContact; //Create empty contact
-
+
OContact* found = m_uidToContact.find( QString().setNum( uid ) );
if ( found ){
foundContact = *found;
}
-
+
return ( foundContact );
}
-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() );
QListIterator<OContact> it( m_contactList );
uint arraycounter = 0;
-
+
for( ; it.current(); ++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;
// If we get an additional date, we
// will take this date instead of
- // the current one..
+ // the current one..
if ( !d.date().isValid() )
current = QDate::currentDate();
else
current = d.date();
// We have to equalize the year, otherwise
// 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() );
// 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 ! ",
+ 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 ) ) ){
allcorrect = false;
qWarning (" Nope!..");
}
}
}
} else{
// checkDate is invalid. Therefore 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
+ | 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> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
{
QArray<int> m_currentQuery( m_contactList.count() );
QListIterator<OContact> it( m_contactList );
uint arraycounter = 0;
-
+
for( ; it.current(); ++it ){
if ( (*it)->match( r ) ){
m_currentQuery[arraycounter++] = (*it)->uid();
}
-
+
}
// Shrink to fit..
m_currentQuery.resize(arraycounter);
-
+
return m_currentQuery;
}
const uint OContactAccessBackend_XML::querySettings()
{
return ( OContactAccess::WildCards
| OContactAccess::IgnoreCase
| OContactAccess::RegExp
- | OContactAccess::ExactMatch
+ | OContactAccess::ExactMatch
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
);
}
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.
* Wildcards, RegExp, ExactMatch should never used at the same time...
*/
-
- if ( querySettings == OContactAccess::IgnoreCase )
+
+ if ( querySettings == OContactAccess::IgnoreCase )
return false;
-
+
switch ( querySettings & ~( OContactAccess::IgnoreCase
| OContactAccess::DateDiff
| OContactAccess::DateYear
| OContactAccess::DateMonth
| OContactAccess::DateDay
- )
+ )
){
case OContactAccess::RegExp:
return ( true );
case OContactAccess::WildCards:
return ( true );
case OContactAccess::ExactMatch:
return ( true );
default:
return ( false );
}
}
-// 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 )
{
QMap<QString, int> nameToUid;
QStringList names;
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..
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() );
}
names.sort();
-
+
int i = 0;
if ( asc ){
for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
m_currentQuery[i++] = nameToUid[ (*it) ];
}else{
for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
m_currentQuery[i++] = nameToUid[ (*it) ];
}
-
+
return m_currentQuery;
-
+
}
bool OContactAccessBackend_XML::add ( const OContact &newcontact )
{
//qWarning("odefaultbackend: ACTION::ADD");
updateJournal (newcontact, ACTION_ADD);
addContact_p( newcontact );
-
+
m_changed = true;
-
+
return true;
}
bool OContactAccessBackend_XML::replace ( const OContact &contact )
{
m_changed = true;
-
+
OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
if ( found ) {
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;
} else
return false;
}
bool OContactAccessBackend_XML::remove ( int uid )
{
m_changed = true;
-
+
OContact* found = m_uidToContact.find ( QString().setNum( uid ) );
if ( found ) {
updateJournal ( *found, ACTION_REMOVE);
m_contactList.removeRef ( found );
m_uidToContact.remove( QString().setNum( uid ) );
return true;
} else
return false;
}
bool OContactAccessBackend_XML::reload(){
/* Reload is the same as load in this implementation */
return ( load() );
}
void OContactAccessBackend_XML::addContact_p( const OContact &newcontact )
{
OContact* contRef = new OContact( newcontact );
m_contactList.append ( contRef );
m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
}
/* 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
* changed externally.
*/
if ( !isJournal ){
QFileInfo fi( filename );
m_readtime = fi.lastModified ();
}
-
+
const int JOURNALACTION = Qtopia::Notes + 1;
const int JOURNALROW = JOURNALACTION + 1;
-
+
bool foundAction = false;
journal_action action = ACTION_ADD;
int journalKey = 0;
QMap<int, QString> contactMap;
QMap<QString, QString> customMap;
QMap<QString, QString>::Iterator customIt;
QAsciiDict<int> dict( 47 );
-
+
dict.setAutoDelete( TRUE );
dict.insert( "Uid", new int(Qtopia::AddressUid) );
dict.insert( "Title", new int(Qtopia::Title) );
dict.insert( "FirstName", new int(Qtopia::FirstName) );
dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
dict.insert( "LastName", new int(Qtopia::LastName) );
dict.insert( "Suffix", new int(Qtopia::Suffix) );
dict.insert( "FileAs", new int(Qtopia::FileAs) );
dict.insert( "Categories", new int(Qtopia::AddressCategory) );
dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
dict.insert( "Emails", new int(Qtopia::Emails) );
dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
dict.insert( "HomeState", new int(Qtopia::HomeState) );
dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
dict.insert( "Company", new int(Qtopia::Company) );
dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
dict.insert( "Department", new int(Qtopia::Department) );
dict.insert( "Office", new int(Qtopia::Office) );
dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
dict.insert( "Profession", new int(Qtopia::Profession) );
dict.insert( "Assistant", new int(Qtopia::Assistant) );
dict.insert( "Manager", new int(Qtopia::Manager) );
dict.insert( "Spouse", new int(Qtopia::Spouse) );
dict.insert( "Children", new int(Qtopia::Children) );
dict.insert( "Gender", new int(Qtopia::Gender) );
dict.insert( "Birthday", new int(Qtopia::Birthday) );
dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
dict.insert( "Nickname", new int(Qtopia::Nickname) );
dict.insert( "Notes", new int(Qtopia::Notes) );
dict.insert( "action", new int(JOURNALACTION) );
dict.insert( "actionrow", new int(JOURNALROW) );
-
+
//qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() );
-
+
XMLElement *root = XMLElement::load( filename );
if(root != 0l ){ // start parsing
/* Parse all XML-Elements and put the data into the
* Contact-Class
*/
XMLElement *element = root->firstChild();
//qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() );
element = element->firstChild();
-
+
/* Search Tag "Contacts" which is the parent of all Contacts */
while( element && !isJournal ){
if( element->tagName() != QString::fromLatin1("Contacts") ){
//qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
// element->tagName().latin1());
element = element->nextChild();
} else {
element = element->firstChild();
break;
}
}
/* Parse all Contacts and ignore unknown tags */
while( element ){
if( element->tagName() != QString::fromLatin1("Contact") ){
//qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s",
// element->tagName().latin1());
element = element->nextChild();
continue;
}
/* Found alement with tagname "contact", now parse and store all
* attributes contained
*/
//qWarning("OContactDefBack::load element tagName() : %s",
// element->tagName().latin1() );
QString dummy;
foundAction = false;
-
+
XMLElement::AttributeMap aMap = element->attributes();
XMLElement::AttributeMap::Iterator it;
contactMap.clear();
customMap.clear();
for( it = aMap.begin(); it != aMap.end(); ++it ){
// qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
-
+
int *find = dict[ it.key() ];
/* Unknown attributes will be stored as "Custom" elements */
if ( !find ) {
qWarning("Attribute %s not known.", it.key().latin1());
//contact.setCustomField(it.key(), it.data());
customMap.insert( it.key(), it.data() );
continue;
}
-
+
/* Check if special conversion is needed and add attribute
* into Contact class
*/
switch( *find ) {
/*
case Qtopia::AddressUid:
contact.setUid( it.data().toInt() );
break;
case Qtopia::AddressCategory:
contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
break;
*/
case JOURNALACTION:
action = journal_action(it.data().toInt());
foundAction = true;
qWarning ("ODefBack(journal)::ACTION found: %d", action);
break;
case JOURNALROW:
journalKey = it.data().toInt();
break;
default: // no conversion needed add them to the map
contactMap.insert( *find, it.data() );
break;
}
}
/* now generate the Contact contact */
OContact contact( contactMap );
-
+
for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
contact.setCustomField( customIt.key(), customIt.data() );
}
-
+
if (foundAction){
foundAction = false;
switch ( action ) {
case ACTION_ADD:
addContact_p (contact);
break;
case ACTION_REMOVE:
if ( !remove (contact.uid()) )
qWarning ("ODefBack(journal)::Unable to remove uid: %d",
contact.uid() );
break;
case ACTION_REPLACE:
if ( !replace ( contact ) )
qWarning ("ODefBack(journal)::Unable to replace uid: %d",
contact.uid() );
break;
default:
qWarning ("Unknown action: ignored !");
break;
}
}else{
/* Add contact to list */
addContact_p (contact);
}
-
+
/* Move to next element */
element = element->nextChild();
}
}else {
qWarning("ODefBack::could not load");
}
delete root;
qWarning("returning from loading" );
return true;
}
void OContactAccessBackend_XML::updateJournal( const OContact& cnt,
- journal_action action )
+ journal_action action )
{
QFile f( m_journalName );
bool created = !f.exists();
if ( !f.open(IO_WriteOnly|IO_Append) )
return;
-
+
QString buf;
QCString str;
-
+
// if the file was created, we have to set the Tag "<CONTACTS>" to
// get a XML-File which is readable by our parser.
// This is just a cheat, but better than rewrite the parser.
if ( created ){
buf = "<Contacts>";
QCString cstr = buf.utf8();
f.writeBlock( cstr.data(), cstr.length() );
}
-
+
buf = "<Contact ";
cnt.save( buf );
buf += " action=\"" + QString::number( (int)action ) + "\" ";
buf += "/>\n";
QCString cstr = buf.utf8();
f.writeBlock( cstr.data(), cstr.length() );
}
void OContactAccessBackend_XML::removeJournal()
{
QFile f ( m_journalName );
if ( f.exists() )
f.remove();
}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index 4d6a7ef..7b5365b 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -1,144 +1,154 @@
/*
* 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.14 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.13 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.12.2.2 2003/02/11 12:17:28 eilers
* Speed optimization. Removed the sequential search loops.
*
* Revision 1.12.2.1 2003/02/09 15:05:01 eilers
* Nothing happened.. Just some cleanup before I will start..
*
* 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 "ocontactaccessbackend.h"
#include "ocontactaccess.h"
#include <qlist.h>
#include <qdict.h>
/* the default xml implementation */
+/**
+ * This class is the XML implementation of a Contact backend
+ * it does implement everything available for OContact.
+ * @see OPimAccessBackend for more information of available methods
+ */
class OContactAccessBackend_XML : public OContactAccessBackend {
public:
- OContactAccessBackend_XML ( QString appname, QString filename = 0l );
-
+ OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null );
+
bool save();
-
+
bool load ();
void clear ();
-
+
bool wasChangedExternally();
-
+
QArray<int> allRecords() const;
-
+
OContact find ( int uid ) const;
-
+
QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() );
QArray<int> matchRegexp( const QRegExp &r ) const;
-
+
const uint querySettings();
-
+
bool hasQuerySettings (uint querySettings) const;
-
- // Currently only asc implemented..
+
+ // Currently only asc implemented..
QArray<int> sorted( bool asc, int , int , int );
bool add ( const OContact &newcontact );
-
+
bool replace ( const OContact &contact );
-
+
bool remove ( int uid );
bool reload();
-
+
private:
enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
void addContact_p( const OContact &newcontact );
-
+
/* This function loads the xml-database and the journalfile */
bool load( const QString filename, bool isJournal );
-
-
+
+
void updateJournal( const OContact& cnt, journal_action action );
void removeJournal();
-
+
protected:
bool m_changed;
QString m_journalName;
QString m_fileName;
QString m_appName;
QList<OContact> m_contactList;
QDateTime m_readtime;
QDict<OContact> m_uidToContact;
};
#endif
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h
index eb6e8fb..86ff298 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.h
@@ -1,32 +1,73 @@
#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H
#define OPIE_DATE_BOOK_ACCESS_BACKEND_H
#include <qarray.h>
#include "opimaccessbackend.h"
#include "oevent.h"
+/**
+ * This class is the interface to the storage of Events.
+ * @see OPimAccessBackend
+ *
+ */
class ODateBookAccessBackend : public OPimAccessBackend<OEvent> {
public:
typedef int UID;
+
+ /**
+ * c'tor without parameter
+ */
ODateBookAccessBackend();
~ODateBookAccessBackend();
+ /**
+ * This method should return a list of UIDs containing
+ * all events. No filter should be applied
+ * @return list of events
+ */
virtual QArray<UID> rawEvents()const = 0;
+
+ /**
+ * This method should return a list of UIDs containing
+ * all repeating events. No filter should be applied
+ * @return list of repeating events
+ */
virtual QArray<UID> rawRepeats()const = 0;
+
+ /**
+ * This mthod should return a list of UIDs containing all non
+ * repeating events. No filter should be applied
+ * @return list of nonrepeating events
+ */
virtual QArray<UID> nonRepeats() const = 0;
/**
- * these two methods are used if you do not implement
- * effectiveEvents...
+ * If you do not want to implement the effectiveEvents methods below
+ * you need to supply it with directNonRepeats.
+ * This method can return empty lists if effectiveEvents is implememted
*/
virtual OEvent::ValueList directNonRepeats() = 0;
+
+ /**
+ * Same as above but return raw repeats!
+ */
virtual OEvent::ValueList directRawRepeats() = 0;
/* is implemented by default but you can reimplement it*/
+ /**
+ * Effective Events are special event occuring during a time frame. This method does calcualte
+ * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
+ * yourself
+ */
virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to );
+
+ /**
+ * this is an overloaded member function
+ * @see effecticeEvents
+ */
virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start );
};
#endif
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
index 563c31f..7848f7c 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
@@ -1,48 +1,54 @@
#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H
#define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H
#include <qmap.h>
#include "odatebookaccessbackend.h"
+/**
+ * This is the default XML implementation for DateBoook XML storage
+ * It fully implements the interface
+ * @see ODateBookAccessBackend
+ * @see OPimAccessBackend
+ */
class ODateBookAccessBackend_XML : public ODateBookAccessBackend {
public:
ODateBookAccessBackend_XML( const QString& appName,
const QString& fileName = QString::null);
~ODateBookAccessBackend_XML();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() );
OEvent find( int uid )const;
void clear();
bool add( const OEvent& ev );
bool remove( int uid );
bool replace( const OEvent& ev );
QArray<UID> rawEvents()const;
QArray<UID> rawRepeats()const;
QArray<UID> nonRepeats()const;
OEvent::ValueList directNonRepeats();
OEvent::ValueList directRawRepeats();
private:
bool m_changed :1 ;
bool loadFile();
inline void finalizeRecord( OEvent& ev );
inline void setField( OEvent&, int field, const QString& val );
QString m_name;
QMap<int, OEvent> m_raw;
QMap<int, OEvent> m_rep;
struct Data;
Data* data;
class Private;
Private *d;
};
#endif
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index 32b2dcb..d7ceaf2 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -1,150 +1,160 @@
/*
* 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.7 2003/04/13 18:07:10 zecke
+ * More API doc
+ * QString -> const QString&
+ * QString = 0l -> QString::null
+ *
* Revision 1.6 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.5 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* 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.
+/**
+ * Class to access the contacts database.
* This is just a frontend for the real database handling which is
* done by the backend.
+ * This class is used to access the Contacts on a system. This class as any OPIE PIM
+ * class is backend independent.
+
* @see OPimAccessTemplate
*/
class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
{
Q_OBJECT
public:
- /** Create Database with contacts (addressbook).
+ /**
+ * 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
DateDiff = 0x0020, // Find all entries from today until given date
DateYear = 0x0040, // The year matches
DateMonth = 0x0080, // The month matches
DateDay = 0x0100, // The day matches
};
-
+
ORecordList<OContact> matchRegexp( const QRegExp &r )const;
/** Return all Contacts in a sorted manner.
* @param ascending true: Sorted in acending order.
* @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess
* @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess
* @param cat Currently not implemented. Just defined to stay compatible to otodoaccess
*/
List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) 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();
signals:
/* Signal is emitted if the database was changed. Therefore
* we may need to reload to stay consistent.
* @param which Pointer to the database who created this event. This pointer
* is useful if an application has to handle multiple databases at the same time.
* @see reload()
*/
void signalChanged ( const OContactAccess *which );
private:
// class OContactAccessPrivate;
// OContactAccessPrivate* d;
OContactAccessBackend *m_backEnd;
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
index 08e61ff..a3661a3 100644
--- a/libopie2/opiepim/core/odatebookaccess.cpp
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -1,38 +1,66 @@
#include "obackendfactory.h"
#include "odatebookaccess.h"
+/**
+ * Simple constructor
+ * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation
+ * will be used!
+ * @param back The backend to be used or 0 for the default backend
+ * @param ac What kind of access is intended
+ */
ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
: OPimAccessTemplate<OEvent>( back )
{
if (!back )
back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null );
m_backEnd = back;
setBackEnd( m_backEnd );
}
ODateBookAccess::~ODateBookAccess() {
}
+
+/**
+ * @return all events available
+ */
ODateBookAccess::List ODateBookAccess::rawEvents()const {
QArray<int> ints = m_backEnd->rawEvents();
List lis( ints, this );
return lis;
}
+
+/**
+ * @return all repeating events
+ */
ODateBookAccess::List ODateBookAccess::rawRepeats()const {
QArray<int> ints = m_backEnd->rawRepeats();
List lis( ints, this );
return lis;
}
+
+/**
+ * @return all non repeating events
+ */
ODateBookAccess::List ODateBookAccess::nonRepeats()const {
QArray<int> ints = m_backEnd->nonRepeats();
List lis( ints, this );
return lis;
}
+
+/**
+ * @return dates in the time span between from and to
+ * @param from Include all events from...
+ * @param to Include all events to...
+ */
OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) {
return m_backEnd->effecticeEvents( from, to );
}
+/**
+ * @return all events at a given datetime
+ */
OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) {
return m_backEnd->effecticeEvents( start );
}
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index 7047039..7c7a63f 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -1,32 +1,41 @@
#ifndef OPIE_DATE_BOOK_ACCESS_H
#define OPIE_DATE_BOOK_ACCESS_H
#include "odatebookaccessbackend.h"
#include "opimaccesstemplate.h"
#include "oevent.h"
+/**
+ * This is the object orientated datebook database. It'll use OBackendFactory
+ * to query for a backend.
+ * All access to the datebook should be done via this class.
+ * Make sure to load and save the datebook this is not part of
+ * destructing and creating the object
+ *
+ * @author Holger Freyther
+ */
class ODateBookAccess : public OPimAccessTemplate<OEvent> {
public:
ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
~ODateBookAccess();
- /** return all events */
+ /* return all events */
List rawEvents()const;
- /** return repeating events */
+ /* return repeating events */
List rawRepeats()const;
- /** return non repeating events */
+ /* return non repeating events */
List nonRepeats()const;
OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to );
OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start );
private:
ODateBookAccessBackend* m_backEnd;
class Private;
Private* d;
};
#endif
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
index 1fd1c75..25fa0e7 100644
--- a/libopie2/opiepim/ocontact.h
+++ b/libopie2/opiepim/ocontact.h
@@ -1,86 +1,93 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __OCONTACT_H__
#define __OCONTACT_H__
#include <opie/opimrecord.h>
#include <qpe/recordfields.h>
#include <qdatetime.h>
#include <qstringlist.h>
#if defined(QPC_TEMPLATEDLL)
// MOC_SKIP_BEGIN
QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
// MOC_SKIP_END
#endif
-class ContactPrivate;
-
+class ContactPrivate;
+
+/**
+ * OContact class represents a specialised PIM Record for contacts.
+ * It does store all kind of persopn related information.
+ *
+ * @short Contact Container
+ * @author TT, Stefan Eiler, Holger Freyther
+ */
class QPC_EXPORT OContact : public OPimRecord
{
friend class DataSet;
public:
OContact();
OContact( const QMap<int, QString> &fromMap );
virtual ~OContact();
/*
* do we need to inline them
* if yes do we need to inline them this way?
* -zecke
*/
void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
void setFileAs();
// default email address
void setDefaultEmail( const QString &v );
// inserts email to list and ensure's doesn't already exist
void insertEmail( const QString &v );
void removeEmail( const QString &v );
void clearEmails();
void insertEmails( const QStringList &v );
// home
void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
// business
void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h
index 585515c..57d32d0 100644
--- a/libopie2/opiepim/oevent.h
+++ b/libopie2/opiepim/oevent.h
@@ -1,195 +1,210 @@
// CONTAINS GPLed code of TT
#ifndef OPIE_PIM_EVENT_H
#define OPIE_PIM_EVENT_H
#include <qstring.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include "otimezone.h"
#include "opimrecord.h"
struct OCalendarHelper {
/** calculate the week number of the date */
static int week( const QDate& );
/** calculate the occurence of week days since the start of the month */
static int ocurrence( const QDate& );
// returns the dayOfWeek for the *first* day it finds (ignores
// any further days!). Returns 1 (Monday) if there isn't any day found
static int dayOfWeek( char day );
/** returns the diff of month */
static int monthDiff( const QDate& first, const QDate& second );
};
class OPimNotifyManager;
class ORecur;
+
+/**
+ * This is the container for all Events. It encapsules all
+ * available information for a single Event
+ * @short container for events.
+ */
class OEvent : public OPimRecord {
public:
typedef QValueList<OEvent> ValueList;
+ /**
+ * RecordFields contain possible attributes
+ */
enum RecordFields {
Uid = Qtopia::UID_ID,
Category = Qtopia::CATEGORY_ID,
Description,
Location,
Alarm,
Reminder,
Recurrence,
Note,
Created,
StartDate,
EndDate,
AllDay,
TimeZone
};
+ /**
+ * Start with an Empty OEvent. UID == 0 means that it is empty
+ */
OEvent(int uid = 0);
+
+ /**
+ * copy c'tor
+ */
OEvent( const OEvent& );
~OEvent();
OEvent &operator=( const OEvent& );
QString description()const;
void setDescription( const QString& description );
QString location()const;
void setLocation( const QString& loc );
bool hasNotifiers()const;
OPimNotifyManager &notifiers()const;
ORecur recurrence()const;
void setRecurrence( const ORecur& );
bool hasRecurrence()const;
QString note()const;
void setNote( const QString& note );
QDateTime createdDateTime()const;
void setCreatedDateTime( const QDateTime& dt);
/** set the date to dt. dt is the QDateTime in localtime */
void setStartDateTime( const QDateTime& );
/** returns the datetime in the local timeZone */
QDateTime startDateTime()const;
/** returns the start datetime in the current zone */
QDateTime startDateTimeInZone()const;
/** in current timezone */
void setEndDateTime( const QDateTime& );
/** in current timezone */
QDateTime endDateTime()const;
QDateTime endDateTimeInZone()const;
bool isMultipleDay()const;
bool isAllDay()const;
void setAllDay( bool isAllDay );
/* pin this event to a timezone! FIXME */
void setTimeZone( const QString& timeZone );
QString timeZone()const;
bool match( const QRegExp& )const;
/** For exception to recurrence here is a list of children... */
QArray<int> children()const;
void setChildren( const QArray<int>& );
void addChild( int uid );
void removeChild( int uid );
/** return the parent OEvent */
int parent()const;
void setParent( int uid );
/* needed reimp */
QString toRichText()const;
QString toShortText()const;
QString type()const;
QMap<int, QString> toMap()const;
QMap<QString, QString> toExtraMap()const;
QString recordField(int )const;
static int rtti();
bool loadFromStream( QDataStream& );
bool saveToStream( QDataStream& )const;
/* bool operator==( const OEvent& );
bool operator!=( const OEvent& );
bool operator<( const OEvent& );
bool operator<=( const OEvent& );
bool operator>( const OEvent& );
bool operator>=(const OEvent& );
*/
private:
inline void changeOrModify();
void deref();
struct Data;
Data* data;
class Private;
Private* priv;
};
/**
* AN Event can span through multiple days. We split up a multiday eve
*/
-
class OEffectiveEvent {
public:
typedef QValueList<OEffectiveEvent> ValueList;
enum Position { MidWay, Start, End, StartEnd };
// If we calculate the effective event of a multi-day event
// we have to figure out whether we are at the first day,
// at the end, or anywhere else ("middle"). This is important
// for the start/end times (00:00/23:59)
// MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
// day event
// Start: start time -> 23:59
// End: 00:00 -> end time
// Start | End == StartEnd: for single-day events (default)
// here we draw start time -> end time
OEffectiveEvent();
OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd );
OEffectiveEvent( const OEffectiveEvent& );
OEffectiveEvent &operator=(const OEffectiveEvent& );
~OEffectiveEvent();
void setStartTime( const QTime& );
void setEndTime( const QTime& );
void setEvent( const OEvent& );
void setDate( const QDate& );
void setEffectiveDates( const QDate& from, const QDate& to );
QString description()const;
QString location()const;
QString note()const;
OEvent event()const;
QTime startTime()const;
QTime endTime()const;
QDate date()const;
/* return the length in hours */
int length()const;
int size()const;
QDate startDate()const;
QDate endDate()const;
bool operator<( const OEffectiveEvent &e ) const;
bool operator<=( const OEffectiveEvent &e ) const;
bool operator==( const OEffectiveEvent &e ) const;
bool operator!=( const OEffectiveEvent &e ) const;
bool operator>( const OEffectiveEvent &e ) const;
bool operator>= ( const OEffectiveEvent &e ) const;