summaryrefslogtreecommitdiff
path: root/libopie/pim
Unidiff
Diffstat (limited to 'libopie/pim') (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 @@
1/*
2 * Class to manage Backends.
3 *
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 *
6 * =====================================================================
7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation;
10 * either version 2 of the License, or (at your option) any later
11 * version.
12 * =====================================================================
13 * ToDo: Use plugins
14 * =====================================================================
15 * Version: $Id$
16 * =====================================================================
17 * History:
18 * $Log$
19 * Revision 1.1 2002/10/07 17:35:01 eilers
20 * added OBackendFactory for advanced backend access
21 *
22 *
23 * =====================================================================
24 */
25#ifndef __OPIE_BACKENDFACTORY_H_
26#define __OPIE_BACKENDFACTORY_H_
27
28#include <qstring.h>
29#include <qasciidict.h>
30#include <qpe/config.h>
31
32#include "otodoaccessxml.h"
33#include "ocontactaccessbackend_xml.h"
34#include "otodoaccesssql.h"
35
36
37template<class T>
38class OBackendFactory
39{
40 public:
41 OBackendFactory() {};
42
43 enum BACKENDS {
44 TODO,
45 CONTACT,
46 DATE
47 };
48
49 static T* Default( const QString backendName, const QString& appName ){
50
51
52 Config config( "pimaccess" );
53 config.setGroup ( backendName );
54 QString backend = config.readEntry( "usebackend" );
55
56 QAsciiDict<int> dict ( 3 );
57 dict.setAutoDelete ( TRUE );
58
59 dict.insert( "todo", new int (TODO) );
60 dict.insert( "contact", new int (CONTACT) );
61
62 qWarning ("TODO is: %d", TODO);
63 qWarning ("CONTACT is: %d", CONTACT);
64
65 switch ( *dict.take( backendName ) ){
66 case TODO:
67 if ( backend == "sql" )
68 return (T*) new OTodoAccessBackendSQL("");
69
70 return (T*) new OTodoAccessXML( appName );
71 case CONTACT:
72 if ( backend == "sql" )
73 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
74
75 return (T*) new OContactAccessBackend_XML( appName );
76 case DATE:
77 qWarning ("OBackendFactory:: DATE-Backend not implemented!");
78 return NULL;
79 default:
80 return NULL;
81 }
82
83
84 }
85};
86
87
88#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
@@ -8,74 +8,80 @@
8 *modify it under the terms of the GNU Library General Public 8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * Info: This class could just work with a change in the header-file 12 * Info: This class could just work with a change in the header-file
13 * of the Contact class ! Therefore our libopie only compiles 13 * of the Contact class ! Therefore our libopie only compiles
14 * with our version of libqpe 14 * with our version of libqpe
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: XML-Backend: Automatic reload if something was changed... 16 * ToDo: XML-Backend: Automatic reload if something was changed...
17 * 17 *
18 * 18 *
19 * ===================================================================== 19 * =====================================================================
20 * Version: $Id$ 20 * Version: $Id$
21 * ===================================================================== 21 * =====================================================================
22 * History: 22 * History:
23 * $Log$ 23 * $Log$
24 * Revision 1.3 2002/10/07 17:34:24 eilers
25 * added OBackendFactory for advanced backend access
26 *
24 * Revision 1.2 2002/10/02 16:18:11 eilers 27 * Revision 1.2 2002/10/02 16:18:11 eilers
25 * debugged and seems to work almost perfectly .. 28 * debugged and seems to work almost perfectly ..
26 * 29 *
27 * Revision 1.1 2002/09/27 17:11:44 eilers 30 * Revision 1.1 2002/09/27 17:11:44 eilers
28 * Added API for accessing the Contact-Database ! It is compiling, but 31 * Added API for accessing the Contact-Database ! It is compiling, but
29 * please do not expect that anything is working ! 32 * please do not expect that anything is working !
30 * I will debug that stuff in the next time .. 33 * I will debug that stuff in the next time ..
31 * Please read README_COMPILE for compiling ! 34 * Please read README_COMPILE for compiling !
32 * 35 *
33 * 36 *
34 */ 37 */
35 38
36#include "ocontactaccess.h" 39#include "ocontactaccess.h"
40#include "obackendfactory.h"
37 41
38#include <qasciidict.h> 42#include <qasciidict.h>
39#include <qdatetime.h> 43#include <qdatetime.h>
40#include <qfile.h> 44#include <qfile.h>
41#include <qregexp.h> 45#include <qregexp.h>
42#include <qlist.h> 46#include <qlist.h>
43#include <qcopchannel_qws.h> 47#include <qcopchannel_qws.h>
44 48
45//#include <qpe/qcopenvelope_qws.h> 49//#include <qpe/qcopenvelope_qws.h>
46#include <qpe/global.h> 50#include <qpe/global.h>
47 51
48#include <errno.h> 52#include <errno.h>
49#include <fcntl.h> 53#include <fcntl.h>
50#include <unistd.h> 54#include <unistd.h>
51#include <stdlib.h> 55#include <stdlib.h>
52 56
53#include "ocontactaccessbackend_xml.h" 57#include "ocontactaccessbackend_xml.h"
54 58
55 59
56OContactAccess::OContactAccess ( const QString appname, const QString filename, 60OContactAccess::OContactAccess ( const QString appname, const QString ,
57 OContactAccessBackend* end, bool autosync ): 61 OContactAccessBackend* end, bool autosync ):
58 OPimAccessTemplate<OContact>( end ), 62 OPimAccessTemplate<OContact>( end ),
59 m_changed ( false ) 63 m_changed ( false )
60{ 64{
61 /* take care of the backend. If there is no one defined, we 65 /* take care of the backend. If there is no one defined, we
62 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 66 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
63 */ 67 */
64 if( end == 0 ) { 68 if( end == 0 ) {
65 end = new OContactAccessBackend_XML( appname, filename ); 69 // __asm__("int3");
70 qWarning ("Using BackendFactory !");
71 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
66 } 72 }
67 // Set backend locally and in template 73 // Set backend locally and in template
68 m_backEnd = end; 74 m_backEnd = end;
69 OPimAccessTemplate<OContact>::setBackEnd (end); 75 OPimAccessTemplate<OContact>::setBackEnd (end);
70 76
71 77
72 /* Connect signal of external db change to function */ 78 /* Connect signal of external db change to function */
73 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 79 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
74 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), 80 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)),
75 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 81 this, SLOT(copMessage( const QCString &, const QByteArray &)) );
76 if ( autosync ){ 82 if ( autosync ){
77 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 83 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
78 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), 84 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)),
79 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 85 this, SLOT(copMessage( const QCString &, const QByteArray &)) );
80 } 86 }
81 87
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
@@ -6,45 +6,49 @@
6 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 6 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
7 * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) 7 * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
8 * 8 *
9 * ===================================================================== 9 * =====================================================================
10 *This program is free software; you can redistribute it and/or 10 *This program is free software; you can redistribute it and/or
11 *modify it under the terms of the GNU Library General Public 11 *modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; 12 * License as published by the Free Software Foundation;
13 * either version 2 of the License, or (at your option) any later 13 * either version 2 of the License, or (at your option) any later
14 * version. 14 * version.
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: Define enum for query settings 16 * ToDo: Define enum for query settings
17 * ===================================================================== 17 * =====================================================================
18 * Version: $Id$ 18 * Version: $Id$
19 * ===================================================================== 19 * =====================================================================
20 * History: 20 * History:
21 * $Log$ 21 * $Log$
22 * Revision 1.2 2002/10/07 17:34:24 eilers
23 * added OBackendFactory for advanced backend access
24 *
22 * Revision 1.1 2002/09/27 17:11:44 eilers 25 * Revision 1.1 2002/09/27 17:11:44 eilers
23 * Added API for accessing the Contact-Database ! It is compiling, but 26 * Added API for accessing the Contact-Database ! It is compiling, but
24 * please do not expect that anything is working ! 27 * please do not expect that anything is working !
25 * I will debug that stuff in the next time .. 28 * I will debug that stuff in the next time ..
26 * Please read README_COMPILE for compiling ! 29 * Please read README_COMPILE for compiling !
27 * 30 *
28 * ===================================================================== 31 * =====================================================================
29 * 32 *
30 */ 33 */
31 34
32#ifndef _OCONTACTACCESSBACKEND_H_ 35#ifndef _OCONTACTACCESSBACKEND_H_
33#define _OCONTACTACCESSBACKEND_H_ 36#define _OCONTACTACCESSBACKEND_H_
34 37
38#include "ocontact.h"
35#include "opimaccessbackend.h" 39#include "opimaccessbackend.h"
36 40
37class OContactAccessBackend: public OPimAccessBackend<OContact> { 41class OContactAccessBackend: public OPimAccessBackend<OContact> {
38 public: 42 public:
39 OContactAccessBackend() {} 43 OContactAccessBackend() {}
40 virtual ~OContactAccessBackend() {} 44 virtual ~OContactAccessBackend() {}
41 45
42 46
43 /** Return if database was changed externally. 47 /** Return if database was changed externally.
44 * This may just make sense on file based databases like a XML-File. 48 * This may just make sense on file based databases like a XML-File.
45 * It is used to prevent to overwrite the current database content 49 * It is used to prevent to overwrite the current database content
46 * if the file was already changed by something else ! 50 * if the file was already changed by something else !
47 * If this happens, we have to reload before save our data. 51 * If this happens, we have to reload before save our data.
48 * If we use real databases, this should be handled by the database 52 * If we use real databases, this should be handled by the database
49 * management system themselve, therefore this function should always return false in 53 * management system themselve, therefore this function should always return false in
50 * this case. It is not our problem to handle this conflict ... 54 * this case. It is not our problem to handle this conflict ...
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
@@ -4,52 +4,62 @@
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 5 *
6 * ===================================================================== 6 * =====================================================================
7 *This program is free software; you can redistribute it and/or 7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * ToDo: XML-Backend: Automatic reload if something was changed... 12 * ToDo: XML-Backend: Automatic reload if something was changed...
13 * 13 *
14 * 14 *
15 * ===================================================================== 15 * =====================================================================
16 * Version: $Id$ 16 * Version: $Id$
17 * ===================================================================== 17 * =====================================================================
18 * History: 18 * History:
19 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/10/07 17:34:24 eilers
21 * added OBackendFactory for advanced backend access
22 *
20 * Revision 1.1 2002/09/27 17:11:44 eilers 23 * Revision 1.1 2002/09/27 17:11:44 eilers
21 * Added API for accessing the Contact-Database ! It is compiling, but 24 * Added API for accessing the Contact-Database ! It is compiling, but
22 * please do not expect that anything is working ! 25 * please do not expect that anything is working !
23 * I will debug that stuff in the next time .. 26 * I will debug that stuff in the next time ..
24 * Please read README_COMPILE for compiling ! 27 * Please read README_COMPILE for compiling !
25 * 28 *
26 * 29 *
27 */ 30 */
28 31
29#ifndef _OContactAccessBackend_XML_ 32#ifndef _OContactAccessBackend_XML_
30#define _OContactAccessBackend_XML_ 33#define _OContactAccessBackend_XML_
31 34
32#include <qasciidict.h> 35#include <qasciidict.h>
33#include <qdatetime.h> 36#include <qdatetime.h>
34#include <qfile.h> 37#include <qfile.h>
38#include <qfileinfo.h>
35#include <qregexp.h> 39#include <qregexp.h>
36#include <qarray.h> 40#include <qarray.h>
37 41
42#include <qpe/global.h>
43
38#include <opie/xmltree.h> 44#include <opie/xmltree.h>
39#include "ocontactaccessbackend.h" 45#include "ocontactaccessbackend.h"
46#include "ocontactaccess.h"
47
48#include <stdlib.h>
49#include <errno.h>
40 50
41using namespace Opie; 51using namespace Opie;
42 52
43/* the default xml implementation */ 53/* the default xml implementation */
44class OContactAccessBackend_XML : public OContactAccessBackend { 54class OContactAccessBackend_XML : public OContactAccessBackend {
45 public: 55 public:
46 OContactAccessBackend_XML ( QString appname, QString filename = 0l ) 56 OContactAccessBackend_XML ( QString appname, QString filename = 0l )
47 { 57 {
48 m_appName = appname; 58 m_appName = appname;
49 59
50 /* Set journalfile name ... */ 60 /* Set journalfile name ... */
51 m_journalName = getenv("HOME"); 61 m_journalName = getenv("HOME");
52 m_journalName +="/.abjournal" + appname; 62 m_journalName +="/.abjournal" + appname;
53 63
54 /* Expecting to access the default filename if nothing else is set */ 64 /* Expecting to access the default filename if nothing else is set */
55 if ( filename.isEmpty() ){ 65 if ( filename.isEmpty() ){