summaryrefslogtreecommitdiff
authoreilers <eilers>2002-12-08 12:48:57 (UTC)
committer eilers <eilers>2002-12-08 12:48:57 (UTC)
commita88b210e6895614027c821bb5cedabc9b06117d3 (patch) (side-by-side diff)
tree1c38097b1935713d165c1087268701657a38fa11
parent6e52c7ae78769be8427b01201aa77c78aef90647 (diff)
downloadopie-a88b210e6895614027c821bb5cedabc9b06117d3.zip
opie-a88b210e6895614027c821bb5cedabc9b06117d3.tar.gz
opie-a88b210e6895614027c821bb5cedabc9b06117d3.tar.bz2
Moved journal-enum from ocontact into i the xml-backend..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.h2
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h24
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h24
-rw-r--r--libopie2/opiepim/ocontact.h2
4 files changed, 30 insertions, 22 deletions
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h
index 65ba43e..1fd1c75 100644
--- a/libopie/pim/ocontact.h
+++ b/libopie/pim/ocontact.h
@@ -1,96 +1,94 @@
/**********************************************************************
** 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 QPC_EXPORT OContact : public OPimRecord
{
friend class DataSet;
public:
OContact();
OContact( const QMap<int, QString> &fromMap );
virtual ~OContact();
- enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
-
/*
* 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 ); }
void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index ae6ec9e..c765ff5 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,67 +1,70 @@
/*
* 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.9 2002/12/08 12:48:57 eilers
+ * Moved journal-enum from ocontact into i the xml-backend..
+ *
* Revision 1.8 2002/11/14 17:04:24 eilers
* Sorting will now work if fullname is identical on some entries
*
* Revision 1.7 2002/11/13 15:02:46 eilers
* Small Bug in sorted fixed
*
* Revision 1.6 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.5 2002/11/01 15:10:42 eilers
* Added regExp-search in database for all fields in a contact.
*
* Revision 1.4 2002/10/16 10:52:40 eilers
* Added some docu to the interface and now using the cache infrastucture by zecke.. :)
*
* Revision 1.3 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.2 2002/10/07 17:34:24 eilers
* added OBackendFactory for advanced backend access
*
* Revision 1.1 2002/09/27 17:11:44 eilers
* Added API for accessing the Contact-Database ! It is compiling, but
* please do not expect that anything is working !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
*
*/
#ifndef _OContactAccessBackend_XML_
#define _OContactAccessBackend_XML_
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
#include <qarray.h>
#include <qmap.h>
#include <qpe/global.h>
#include <opie/xmltree.h>
#include "ocontactaccessbackend.h"
#include "ocontactaccess.h"
#include <stdlib.h>
@@ -297,172 +300,175 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
{
/* OContactAccess::IgnoreCase may be added with one
* of the other settings, but never used alone.
* The other settings are just valid alone...
*/
switch ( querySettings & ~OContactAccess::IgnoreCase ){
case OContactAccess::RegExp:
return ( true );
case OContactAccess::WildCards:
return ( true );
case OContactAccess::ExactMatch:
return ( true );
default:
return ( false );
}
}
// Currently only asc implemented..
QArray<int> 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
// Afterwards sort namelist and use map to fill array to return..
QValueListConstIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
names.append( (*it).fileAs() + QString::number( (*it).uid() ) );
nameToUid.insert( (*it).fileAs() + QString::number( (*it).uid() ), (*it).uid() );
}
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 add ( const OContact &newcontact )
{
//qWarning("odefaultbackend: ACTION::ADD");
- updateJournal (newcontact, OContact::ACTION_ADD);
+ updateJournal (newcontact, ACTION_ADD);
addContact_p( newcontact );
m_changed = true;
return true;
}
bool replace ( const OContact &contact )
{
m_changed = true;
bool found = false;
QValueListIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ( (*it).uid() == contact.uid() ){
found = true;
break;
}
}
if (found) {
- updateJournal (contact, OContact::ACTION_REPLACE);
+ updateJournal (contact, ACTION_REPLACE);
m_contactList.remove (it);
m_contactList.append (contact);
return true;
} else
return false;
}
bool remove ( int uid )
{
m_changed = true;
bool found = false;
QValueListIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ((*it).uid() == uid){
found = true;
break;
}
}
if (found) {
- updateJournal ( *it, OContact::ACTION_REMOVE);
+ updateJournal ( *it, ACTION_REMOVE);
m_contactList.remove (it);
return true;
} else
return false;
}
bool reload(){
/* Reload is the same as load in this implementation */
return ( load() );
}
private:
+
+ enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
+
void addContact_p( const OContact &newcontact ){
m_contactList.append (newcontact);
}
/* This function loads the xml-database and the journalfile */
bool 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;
- OContact::journal_action action = OContact::ACTION_ADD;
+ 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) );
@@ -493,148 +499,148 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
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 = OContact::journal_action(it.data().toInt());
+ 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 OContact::ACTION_ADD:
+ case ACTION_ADD:
addContact_p (contact);
break;
- case OContact::ACTION_REMOVE:
+ case ACTION_REMOVE:
if ( !remove (contact.uid()) )
qWarning ("ODefBack(journal)::Unable to remove uid: %d",
contact.uid() );
break;
- case OContact::ACTION_REPLACE:
+ 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 updateJournal( const OContact& cnt,
- OContact::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 removeJournal()
{
QFile f ( m_journalName );
if ( f.exists() )
f.remove();
}
protected:
bool m_changed;
QString m_journalName;
QString m_fileName;
QString m_appName;
QValueList<OContact> m_contactList;
QDateTime m_readtime;
};
#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index ae6ec9e..c765ff5 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -1,67 +1,70 @@
/*
* 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.9 2002/12/08 12:48:57 eilers
+ * Moved journal-enum from ocontact into i the xml-backend..
+ *
* Revision 1.8 2002/11/14 17:04:24 eilers
* Sorting will now work if fullname is identical on some entries
*
* Revision 1.7 2002/11/13 15:02:46 eilers
* Small Bug in sorted fixed
*
* Revision 1.6 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.5 2002/11/01 15:10:42 eilers
* Added regExp-search in database for all fields in a contact.
*
* Revision 1.4 2002/10/16 10:52:40 eilers
* Added some docu to the interface and now using the cache infrastucture by zecke.. :)
*
* Revision 1.3 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.2 2002/10/07 17:34:24 eilers
* added OBackendFactory for advanced backend access
*
* Revision 1.1 2002/09/27 17:11:44 eilers
* Added API for accessing the Contact-Database ! It is compiling, but
* please do not expect that anything is working !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
*
*/
#ifndef _OContactAccessBackend_XML_
#define _OContactAccessBackend_XML_
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
#include <qarray.h>
#include <qmap.h>
#include <qpe/global.h>
#include <opie/xmltree.h>
#include "ocontactaccessbackend.h"
#include "ocontactaccess.h"
#include <stdlib.h>
@@ -297,172 +300,175 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
{
/* OContactAccess::IgnoreCase may be added with one
* of the other settings, but never used alone.
* The other settings are just valid alone...
*/
switch ( querySettings & ~OContactAccess::IgnoreCase ){
case OContactAccess::RegExp:
return ( true );
case OContactAccess::WildCards:
return ( true );
case OContactAccess::ExactMatch:
return ( true );
default:
return ( false );
}
}
// Currently only asc implemented..
QArray<int> 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
// Afterwards sort namelist and use map to fill array to return..
QValueListConstIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
names.append( (*it).fileAs() + QString::number( (*it).uid() ) );
nameToUid.insert( (*it).fileAs() + QString::number( (*it).uid() ), (*it).uid() );
}
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 add ( const OContact &newcontact )
{
//qWarning("odefaultbackend: ACTION::ADD");
- updateJournal (newcontact, OContact::ACTION_ADD);
+ updateJournal (newcontact, ACTION_ADD);
addContact_p( newcontact );
m_changed = true;
return true;
}
bool replace ( const OContact &contact )
{
m_changed = true;
bool found = false;
QValueListIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ( (*it).uid() == contact.uid() ){
found = true;
break;
}
}
if (found) {
- updateJournal (contact, OContact::ACTION_REPLACE);
+ updateJournal (contact, ACTION_REPLACE);
m_contactList.remove (it);
m_contactList.append (contact);
return true;
} else
return false;
}
bool remove ( int uid )
{
m_changed = true;
bool found = false;
QValueListIterator<OContact> it;
for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
if ((*it).uid() == uid){
found = true;
break;
}
}
if (found) {
- updateJournal ( *it, OContact::ACTION_REMOVE);
+ updateJournal ( *it, ACTION_REMOVE);
m_contactList.remove (it);
return true;
} else
return false;
}
bool reload(){
/* Reload is the same as load in this implementation */
return ( load() );
}
private:
+
+ enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
+
void addContact_p( const OContact &newcontact ){
m_contactList.append (newcontact);
}
/* This function loads the xml-database and the journalfile */
bool 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;
- OContact::journal_action action = OContact::ACTION_ADD;
+ 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) );
@@ -493,148 +499,148 @@ class OContactAccessBackend_XML : public OContactAccessBackend {
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 = OContact::journal_action(it.data().toInt());
+ 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 OContact::ACTION_ADD:
+ case ACTION_ADD:
addContact_p (contact);
break;
- case OContact::ACTION_REMOVE:
+ case ACTION_REMOVE:
if ( !remove (contact.uid()) )
qWarning ("ODefBack(journal)::Unable to remove uid: %d",
contact.uid() );
break;
- case OContact::ACTION_REPLACE:
+ 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 updateJournal( const OContact& cnt,
- OContact::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 removeJournal()
{
QFile f ( m_journalName );
if ( f.exists() )
f.remove();
}
protected:
bool m_changed;
QString m_journalName;
QString m_fileName;
QString m_appName;
QValueList<OContact> m_contactList;
QDateTime m_readtime;
};
#endif
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
index 65ba43e..1fd1c75 100644
--- a/libopie2/opiepim/ocontact.h
+++ b/libopie2/opiepim/ocontact.h
@@ -1,96 +1,94 @@
/**********************************************************************
** 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 QPC_EXPORT OContact : public OPimRecord
{
friend class DataSet;
public:
OContact();
OContact( const QMap<int, QString> &fromMap );
virtual ~OContact();
- enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
-
/*
* 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 ); }
void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }