summaryrefslogtreecommitdiff
path: root/libopie
Side-by-side diff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/obackendfactory.h88
-rw-r--r--libopie/pim/ocontactaccess.cpp10
-rw-r--r--libopie/pim/ocontactaccessbackend.h4
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.h10
4 files changed, 110 insertions, 2 deletions
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h
new file mode 100644
index 0000000..599fbf2
--- a/dev/null
+++ b/libopie/pim/obackendfactory.h
@@ -0,0 +1,88 @@
+/*
+ * 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.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 "otodoaccesssql.h"
+
+
+template<class T>
+class OBackendFactory
+{
+ public:
+ OBackendFactory() {};
+
+ enum BACKENDS {
+ TODO,
+ CONTACT,
+ DATE
+ };
+
+ static T* Default( const QString backendName, const QString& appName ){
+
+
+ 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) );
+
+ qWarning ("TODO is: %d", TODO);
+ qWarning ("CONTACT is: %d", CONTACT);
+
+ switch ( *dict.take( backendName ) ){
+ case TODO:
+ if ( backend == "sql" )
+ return (T*) new OTodoAccessBackendSQL("");
+
+ 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:
+ qWarning ("OBackendFactory:: DATE-Backend not implemented!");
+ return NULL;
+ default:
+ return NULL;
+ }
+
+
+ }
+};
+
+
+#endif
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp
index 8a8ff08..b5f358b 100644
--- a/libopie/pim/ocontactaccess.cpp
+++ b/libopie/pim/ocontactaccess.cpp
@@ -1,89 +1,95 @@
/*
* Class to manage the Contacts.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* =====================================================================
* Info: This class could just work with a change in the header-file
* of the Contact class ! Therefore our libopie only compiles
* with our version of libqpe
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.3 2002/10/07 17:34:24 eilers
+ * added OBackendFactory for advanced backend access
+ *
* Revision 1.2 2002/10/02 16:18:11 eilers
* debugged and seems to work almost perfectly ..
*
* Revision 1.1 2002/09/27 17:11:44 eilers
* Added API for accessing the Contact-Database ! It is compiling, but
* please do not expect that anything is working !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
*
*/
#include "ocontactaccess.h"
+#include "obackendfactory.h"
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qregexp.h>
#include <qlist.h>
#include <qcopchannel_qws.h>
//#include <qpe/qcopenvelope_qws.h>
#include <qpe/global.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "ocontactaccessbackend_xml.h"
-OContactAccess::OContactAccess ( const QString appname, const QString filename,
+OContactAccess::OContactAccess ( const QString appname, const QString ,
OContactAccessBackend* end, bool autosync ):
OPimAccessTemplate<OContact>( end ),
m_changed ( false )
{
/* take care of the backend. If there is no one defined, we
* will use the XML-Backend as default (until we have a cute SQL-Backend..).
*/
if( end == 0 ) {
- end = new OContactAccessBackend_XML( appname, filename );
+ // __asm__("int3");
+ qWarning ("Using BackendFactory !");
+ end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
}
// Set backend locally and in template
m_backEnd = end;
OPimAccessTemplate<OContact>::setBackEnd (end);
/* Connect signal of external db change to function */
QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(copMessage( const QCString &, const QByteArray &)) );
if ( autosync ){
QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(copMessage( const QCString &, const QByteArray &)) );
}
}
OContactAccess::~OContactAccess ()
{
/* The user may forget to save the changed database, therefore try to
* do it for him..
*/
if ( m_changed )
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h
index 9469bbc..a651477 100644
--- a/libopie/pim/ocontactaccessbackend.h
+++ b/libopie/pim/ocontactaccessbackend.h
@@ -1,58 +1,62 @@
/**
* 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.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"
class OContactAccessBackend: public OPimAccessBackend<OContact> {
public:
OContactAccessBackend() {}
virtual ~OContactAccessBackend() {}
/** Return if database was changed externally.
* This may just make sense on file based databases like a XML-File.
* It is used to prevent to overwrite the current database content
* if the file was already changed by something else !
* If this happens, we have to reload before save our data.
* If we use real databases, this should be handled by the database
* management system themselve, therefore this function should always return false in
* this case. It is not our problem to handle this conflict ...
* @return <i>true</i> if the database was changed and if save without reload will
* be dangerous. <i>false</i> if the database was not changed or it is save to write
* in this situation.
*/
virtual bool wasChangedExternally() = 0;
/** Return all possible settings.
* @return All settings provided by the current backend
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h
index 2cdb45b..97ef40f 100644
--- a/libopie/pim/ocontactaccessbackend_xml.h
+++ b/libopie/pim/ocontactaccessbackend_xml.h
@@ -1,63 +1,73 @@
/*
* 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.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 <qpe/global.h>
+
#include <opie/xmltree.h>
#include "ocontactaccessbackend.h"
+#include "ocontactaccess.h"
+
+#include <stdlib.h>
+#include <errno.h>
using namespace Opie;
/* the default xml implementation */
class OContactAccessBackend_XML : public OContactAccessBackend {
public:
OContactAccessBackend_XML ( QString appname, QString filename = 0l )
{
m_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 ();
}