summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/backend') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h242
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp36
2 files changed, 140 insertions, 138 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 6f46652..3680ded 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -31,30 +31,36 @@
* ToDo: Use plugins
* =====================================================================
*/
#ifndef OPIE_BACKENDFACTORY_H_
#define OPIE_BACKENDFACTORY_H_
-#include <qstring.h>
-#include <qasciidict.h>
-#include <qpe/config.h>
-
+/* OPIE */
#include <opie2/opimaccessbackend.h>
#include <opie2/opimglobal.h>
#include <opie2/otodoaccessxml.h>
#include <opie2/otodoaccessvcal.h>
#include <opie2/ocontactaccessbackend_xml.h>
#include <opie2/ocontactaccessbackend_vcard.h>
#include <opie2/odatebookaccessbackend_xml.h>
+#include <opie2/odebug.h>
#ifdef __USE_SQL
#include <opie2/otodoaccesssql.h>
#include <opie2/ocontactaccessbackend_sql.h>
#include <opie2/odatebookaccessbackend_sql.h>
#endif
+#include <qpe/config.h>
+
+/* QT */
+#include <qstring.h>
+#include <qasciidict.h>
+
+
+
using namespace Opie;
using namespace Opie::Pim;
namespace Opie {
class OBackendPrivate;
@@ -75,150 +81,150 @@ class OBackendPrivate;
* @version 0.1
*/
template<class T>
class OBackendFactory
{
public:
- OBackendFactory() {};
+ OBackendFactory() {};
/**
* Returns a selected backend implementation
* @param type the type of the backend
- * @param database the type of the used database
+ * @param database the type of the used database
* @param appName The name of your application. It will be passed on to the backend.
- * @param filename Filename of the database file if you don't want to access the default
- * @see OPimGlobal()
+ * @param filename Filename of the database file if you don't want to access the default
+ * @see OPimGlobal()
*/
- static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
- const QString& appName, const QString& filename = QString::null ){
- qWarning("Selected backend for %d is: %d", type, database );
- // If we should use the dafult database style, we have to request it
- OPimGlobal::DatabaseStyle use_database = database;
- if ( use_database == OPimGlobal::DEFAULT ){
- use_database = defaultDB( type );
- }
-
- switch ( type ){
- case OPimGlobal::TODOLIST:
-
- switch ( use_database ){
- default: // Use SQL if something weird is given.
- // Fall through !!
- case OPimGlobal::SQL:
+ static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
+ const QString& appName, const QString& filename = QString::null ){
+ owarn << "Selected backend for " << type << " is: " << database << oendl;
+ // If we should use the dafult database style, we have to request it
+ OPimGlobal::DatabaseStyle use_database = database;
+ if ( use_database == OPimGlobal::DEFAULT ){
+ use_database = defaultDB( type );
+ }
+
+ switch ( type ){
+ case OPimGlobal::TODOLIST:
+
+ switch ( use_database ){
+ default: // Use SQL if something weird is given.
+ // Fall through !!
+ case OPimGlobal::SQL:
#ifdef __USE_SQL
- return (T*) new OPimTodoAccessBackendSQL( filename );
- break;
+ return (T*) new OPimTodoAccessBackendSQL( filename );
+ break;
#else
- qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!");
- // Fall through !!
+ owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl;
+ // Fall through !!
#endif
- case OPimGlobal::XML:
- return (T*) new OPimTodoAccessXML( appName, filename );
- break;
- case OPimGlobal::VCARD:
- return (T*) new OPimTodoAccessVCal( filename );
- break;
- }
- case OPimGlobal::CONTACTLIST:
- switch ( use_database ){
- default: // Use SQL if something weird is given.
- // Fall through !!
- case OPimGlobal::SQL:
+ case OPimGlobal::XML:
+ return (T*) new OPimTodoAccessXML( appName, filename );
+ break;
+ case OPimGlobal::VCARD:
+ return (T*) new OPimTodoAccessVCal( filename );
+ break;
+ }
+ case OPimGlobal::CONTACTLIST:
+ switch ( use_database ){
+ default: // Use SQL if something weird is given.
+ // Fall through !!
+ case OPimGlobal::SQL:
#ifdef __USE_SQL
- return (T*) new OPimContactAccessBackend_SQL( appName, filename );
- break;
+ return (T*) new OPimContactAccessBackend_SQL( appName, filename );
+ break;
#else
- qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!");
- // Fall through !!
+ owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl;
+ // Fall through !!
#endif
- case OPimGlobal::XML:
- return (T*) new OPimContactAccessBackend_XML( appName, filename );
- break;
- case OPimGlobal::VCARD:
- return (T*) new OPimContactAccessBackend_VCard( appName, filename );
- break;
- }
- case OPimGlobal::DATEBOOK:
- switch ( use_database ){
- default: // Use SQL if something weird is given.
- // Fall through !!
- case OPimGlobal::SQL:
+ case OPimGlobal::XML:
+ return (T*) new OPimContactAccessBackend_XML( appName, filename );
+ break;
+ case OPimGlobal::VCARD:
+ return (T*) new OPimContactAccessBackend_VCard( appName, filename );
+ break;
+ }
+ case OPimGlobal::DATEBOOK:
+ switch ( use_database ){
+ default: // Use SQL if something weird is given.
+ // Fall through !!
+ case OPimGlobal::SQL:
#ifdef __USE_SQL
- return (T*) new ODateBookAccessBackend_SQL( appName, filename );
- break;
+ return (T*) new ODateBookAccessBackend_SQL( appName, filename );
+ break;
#else
- qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!");
- // Fall through !!
+ owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl;
+ // Fall through !!
#endif
- case OPimGlobal::XML:
- return (T*) new ODateBookAccessBackend_XML( appName, filename );
- break;
- case OPimGlobal::VCARD:
- qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!");
- return (T*) NULL;
- break;
- }
- default:
- return (T*) NULL;
- }
-
- }
-
- /**
- * Returns the style of the default database which is used to contact PIM data.
+ case OPimGlobal::XML:
+ return (T*) new ODateBookAccessBackend_XML( appName, filename );
+ break;
+ case OPimGlobal::VCARD:
+ owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl;
+ return (T*) NULL;
+ break;
+ }
+ default:
+ return (T*) NULL;
+ }
+
+ }
+
+ /**
+ * Returns the style of the default database which is used to contact PIM data.
* @param type the type of the backend
- * @see OPimGlobal()
- */
- static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
- QString group_name;
- switch ( type ){
- case OPimGlobal::TODOLIST:
- group_name = "todo";
- break;
- case OPimGlobal::CONTACTLIST:
- group_name = "contact";
- break;
- case OPimGlobal::DATEBOOK:
- group_name = "datebook";
- break;
- default:
- group_name = "unknown";
- }
-
- Config config( "pimaccess" );
- config.setGroup ( group_name );
- QString db_String = config.readEntry( "usebackend", "xml" );
-
- QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
- dictDbTypes.setAutoDelete( TRUE );
-
- dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
- dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
- dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
-
- int* db_find = dictDbTypes[ db_String ];
-
- if ( !db_find )
- return OPimGlobal::UNKNOWN;
-
- return (OPimGlobal::DatabaseStyle) *db_find;
- }
+ * @see OPimGlobal()
+ */
+ static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
+ QString group_name;
+ switch ( type ){
+ case OPimGlobal::TODOLIST:
+ group_name = "todo";
+ break;
+ case OPimGlobal::CONTACTLIST:
+ group_name = "contact";
+ break;
+ case OPimGlobal::DATEBOOK:
+ group_name = "datebook";
+ break;
+ default:
+ group_name = "unknown";
+ }
+
+ Config config( "pimaccess" );
+ config.setGroup ( group_name );
+ QString db_String = config.readEntry( "usebackend", "xml" );
+
+ QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
+ dictDbTypes.setAutoDelete( TRUE );
+
+ dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
+ dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
+ dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
+
+ int* db_find = dictDbTypes[ db_String ];
+
+ if ( !db_find )
+ return OPimGlobal::UNKNOWN;
+
+ return (OPimGlobal::DatabaseStyle) *db_find;
+ }
/**
* Returns the default backend implementation for backendName. Which one is used, is defined
- * by the configfile "pimaccess.conf".
+ * by the configfile "pimaccess.conf".
* @param type The type of the backend (@see OPimGlobal())
* @param appName The name of your application. It will be passed on to the backend
- * @see OPimGlobal()
+ * @see OPimGlobal()
*/
- static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){
- return create( type, OPimGlobal::DEFAULT, appName );
- }
+ static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){
+ return create( type, OPimGlobal::DEFAULT, appName );
+ }
private:
- OBackendPrivate* d;
+ OBackendPrivate* d;
};
}
#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 5ffcb11..00d62ee 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -134,14 +134,14 @@ bool OPimContactAccessBackend_XML::save()
}
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 );
+ owarn << "problem renaming file " << strNewFile << " to " << m_journalName
+ << ", errno: " << errno << oendl;
// remove the tmp file...
QFile::remove( strNewFile );
}
/* The journalfile should be removed now... */
removeJournal();
@@ -275,21 +275,19 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
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 ! ",
- checkDate->toString().latin1(),
- current.toString().latin1(),
- queryDate->toString().latin1() );
+ owarn << "Checking if " << checkDate->toString() << " is between " << current.toString()
+ << " and " << queryDate->toString() << " ! " << oendl;
if ( current.daysTo( *queryDate ) >= 0 ){
if ( !( ( *checkDate >= current ) &&
( *checkDate <= *queryDate ) ) ){
allcorrect = false;
- qWarning (" Nope!..");
+ owarn << " Nope!.." << oendl;
}
}
}
} else{
// checkDate is invalid. Therefore this entry is always rejected
allcorrect = false;
@@ -604,42 +602,42 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
//owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
element = element->firstChild();
/* Search Tag "Contacts" which is the parent of all Contacts */
while( element && !isJournal ){
if( element->tagName() != QString::fromLatin1("Contacts") ){
- //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
- // element->tagName().latin1());
+ //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: "
+ // << element->tagName() << oendl;
element = element->nextChild();
} else {
element = element->firstChild();
break;
}
}
/* Parse all Contacts and ignore unknown tags */
while( element ){
if( element->tagName() != QString::fromLatin1("Contact") ){
- //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s",
- // element->tagName().latin1());
+ //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: "
+ // << element->tagName() << oendl;
element = element->nextChild();
continue;
}
/* Found alement with tagname "contact", now parse and store all
* attributes contained
*/
- //qWarning("OPimContactDefBack::load element tagName() : %s",
- // element->tagName().latin1() );
+ //owarn << "OPimContactDefBack::load element tagName() : "
+ // << element->tagName() << oendl;
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());
+ // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl;
int *find = dict[ it.key() ];
/* Unknown attributes will be stored as "Custom" elements */
if ( !find ) {
// owarn << "Attribute " << it.key() << " not known." << oendl;
//contact.setCustomField(it.key(), it.data());
@@ -659,13 +657,13 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
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);
+ owarn << "ODefBack(journal)::ACTION found: " << action << oendl;
break;
case JOURNALROW:
journalKey = it.data().toInt();
break;
default: // no conversion needed add them to the map
contactMap.insert( *find, it.data() );
@@ -684,22 +682,20 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
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() );
+ owarn << "ODefBack(journal)::Unable to remove uid: " << contact.uid() << oendl;
break;
case ACTION_REPLACE:
if ( !replace ( contact ) )
- qWarning ("ODefBack(journal)::Unable to replace uid: %d",
- contact.uid() );
+ owarn << "ODefBack(journal)::Unable to replace uid: " << contact.uid() << oendl;
break;
default:
- qWarning ("Unknown action: ignored !");
+ owarn << "Unknown action: ignored !" << oendl;
break;
}
}else{
/* Add contact to list */
addContact_p (contact);
}