summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h276
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp38
2 files changed, 157 insertions, 157 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 3680ded..9f3a823 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -57,174 +57,174 @@
57#include <qasciidict.h> 57#include <qasciidict.h>
58 58
59 59
60 60
61using namespace Opie; 61using namespace Opie;
62using namespace Opie::Pim; 62using namespace Opie::Pim;
63 63
64namespace Opie { 64namespace Opie {
65 65
66class OBackendPrivate; 66class OBackendPrivate;
67 67
68/** 68/**
69 * This class is our factory. It will give us the default implementations 69 * This class is our factory. It will give us the default implementations
70 * of at least Todolist, Contacts and Datebook. In the future this class will 70 * of at least Todolist, Contacts and Datebook. In the future this class will
71 * allow users to switch the backend with ( XML->SQLite ) without the need 71 * allow users to switch the backend with ( XML->SQLite ) without the need
72 * to recompile.# 72 * to recompile.#
73 * This class - as the whole PIM Api - is making use of templates 73 * This class - as the whole PIM Api - is making use of templates
74 * 74 *
75 * <pre> 75 * <pre>
76 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null ); 76 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null );
77 * backend->load(); 77 * backend->load();
78 * </pre> 78 * </pre>
79 * 79 *
80 * @author Stefan Eilers 80 * @author Stefan Eilers
81 * @version 0.1 81 * @version 0.1
82 */ 82 */
83template<class T> 83 template<class T>
84class OBackendFactory 84 class OBackendFactory
85{ 85 {
86 public: 86 public:
87 OBackendFactory() {}; 87 OBackendFactory() {};
88 88
89 /** 89 /**
90 * Returns a selected backend implementation 90 * Returns a selected backend implementation
91 * @param type the type of the backend 91 * @param type the type of the backend
92 * @param database the type of the used database 92 * @param database the type of the used database
93 * @param appName The name of your application. It will be passed on to the backend. 93 * @param appName The name of your application. It will be passed on to the backend.
94 * @param filename Filename of the database file if you don't want to access the default 94 * @param filename Filename of the database file if you don't want to access the default
95 * @see OPimGlobal() 95 * @see OPimGlobal()
96 */ 96 */
97 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, 97 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
98 const QString& appName, const QString& filename = QString::null ){ 98 const QString& appName, const QString& filename = QString::null ){
99 owarn << "Selected backend for " << type << " is: " << database << oendl; 99 owarn << "Selected backend for " << type << " is: " << database << oendl;
100 // If we should use the dafult database style, we have to request it 100 // If we should use the dafult database style, we have to request it
101 OPimGlobal::DatabaseStyle use_database = database; 101 OPimGlobal::DatabaseStyle use_database = database;
102 if ( use_database == OPimGlobal::DEFAULT ){ 102 if ( use_database == OPimGlobal::DEFAULT ){
103 use_database = defaultDB( type ); 103 use_database = defaultDB( type );
104 } 104 }
105 105
106 switch ( type ){ 106 switch ( type ){
107 case OPimGlobal::TODOLIST: 107 case OPimGlobal::TODOLIST:
108 108
109 switch ( use_database ){ 109 switch ( use_database ){
110 default: // Use SQL if something weird is given. 110 default: // Use SQL if something weird is given.
111 // Fall through !! 111 // Fall through !!
112 case OPimGlobal::SQL: 112 case OPimGlobal::SQL:
113#ifdef __USE_SQL 113#ifdef __USE_SQL
114 return (T*) new OPimTodoAccessBackendSQL( filename ); 114 return (T*) new OPimTodoAccessBackendSQL( filename );
115 break; 115 break;
116#else 116#else
117 owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl; 117 owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl;
118 // Fall through !! 118 // Fall through !!
119#endif 119#endif
120 case OPimGlobal::XML: 120 case OPimGlobal::XML:
121 return (T*) new OPimTodoAccessXML( appName, filename ); 121 return (T*) new OPimTodoAccessXML( appName, filename );
122 break; 122 break;
123 case OPimGlobal::VCARD: 123 case OPimGlobal::VCARD:
124 return (T*) new OPimTodoAccessVCal( filename ); 124 return (T*) new OPimTodoAccessVCal( filename );
125 break; 125 break;
126 } 126 }
127 case OPimGlobal::CONTACTLIST: 127 case OPimGlobal::CONTACTLIST:
128 switch ( use_database ){ 128 switch ( use_database ){
129 default: // Use SQL if something weird is given. 129 default: // Use SQL if something weird is given.
130 // Fall through !! 130 // Fall through !!
131 case OPimGlobal::SQL: 131 case OPimGlobal::SQL:
132#ifdef __USE_SQL 132#ifdef __USE_SQL
133 return (T*) new OPimContactAccessBackend_SQL( appName, filename ); 133 return (T*) new OPimContactAccessBackend_SQL( appName, filename );
134 break; 134 break;
135#else 135#else
136 owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl; 136 owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl;
137 // Fall through !! 137 // Fall through !!
138#endif 138#endif
139 case OPimGlobal::XML: 139 case OPimGlobal::XML:
140 return (T*) new OPimContactAccessBackend_XML( appName, filename ); 140 return (T*) new OPimContactAccessBackend_XML( appName, filename );
141 break; 141 break;
142 case OPimGlobal::VCARD: 142 case OPimGlobal::VCARD:
143 return (T*) new OPimContactAccessBackend_VCard( appName, filename ); 143 return (T*) new OPimContactAccessBackend_VCard( appName, filename );
144 break; 144 break;
145 } 145 }
146 case OPimGlobal::DATEBOOK: 146 case OPimGlobal::DATEBOOK:
147 switch ( use_database ){ 147 switch ( use_database ){
148 default: // Use SQL if something weird is given. 148 default: // Use SQL if something weird is given.
149 // Fall through !! 149 // Fall through !!
150 case OPimGlobal::SQL: 150 case OPimGlobal::SQL:
151#ifdef __USE_SQL 151#ifdef __USE_SQL
152 return (T*) new ODateBookAccessBackend_SQL( appName, filename ); 152 return (T*) new ODateBookAccessBackend_SQL( appName, filename );
153 break; 153 break;
154#else 154#else
155 owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl; 155 owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl;
156 // Fall through !! 156 // Fall through !!
157#endif 157#endif
158 case OPimGlobal::XML: 158 case OPimGlobal::XML:
159 return (T*) new ODateBookAccessBackend_XML( appName, filename ); 159 return (T*) new ODateBookAccessBackend_XML( appName, filename );
160 break; 160 break;
161 case OPimGlobal::VCARD: 161 case OPimGlobal::VCARD:
162 owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl; 162 owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl;
163 return (T*) NULL; 163 return (T*) NULL;
164 break; 164 break;
165 } 165 }
166 default: 166 default:
167 return (T*) NULL; 167 return (T*) NULL;
168 } 168 }
169 169
170 } 170 }
171 171
172 /** 172 /**
173 * Returns the style of the default database which is used to contact PIM data. 173 * Returns the style of the default database which is used to contact PIM data.
174 * @param type the type of the backend 174 * @param type the type of the backend
175 * @see OPimGlobal() 175 * @see OPimGlobal()
176 */ 176 */
177 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ 177 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
178 QString group_name; 178 QString group_name;
179 switch ( type ){ 179 switch ( type ){
180 case OPimGlobal::TODOLIST: 180 case OPimGlobal::TODOLIST:
181 group_name = "todo"; 181 group_name = "todo";
182 break; 182 break;
183 case OPimGlobal::CONTACTLIST: 183 case OPimGlobal::CONTACTLIST:
184 group_name = "contact"; 184 group_name = "contact";
185 break; 185 break;
186 case OPimGlobal::DATEBOOK: 186 case OPimGlobal::DATEBOOK:
187 group_name = "datebook"; 187 group_name = "datebook";
188 break; 188 break;
189 default: 189 default:
190 group_name = "unknown"; 190 group_name = "unknown";
191 } 191 }
192 192
193 Config config( "pimaccess" ); 193 Config config( "pimaccess" );
194 config.setGroup ( group_name ); 194 config.setGroup ( group_name );
195 QString db_String = config.readEntry( "usebackend", "xml" ); 195 QString db_String = config.readEntry( "usebackend", "xml" );
196 196
197 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); 197 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
198 dictDbTypes.setAutoDelete( TRUE ); 198 dictDbTypes.setAutoDelete( TRUE );
199 199
200 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); 200 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
201 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); 201 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
202 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); 202 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
203 203
204 int* db_find = dictDbTypes[ db_String ]; 204 int* db_find = dictDbTypes[ db_String ];
205 205
206 if ( !db_find ) 206 if ( !db_find )
207 return OPimGlobal::UNKNOWN; 207 return OPimGlobal::UNKNOWN;
208 208
209 return (OPimGlobal::DatabaseStyle) *db_find; 209 return (OPimGlobal::DatabaseStyle) *db_find;
210 } 210 }
211 211
212 212
213 /** 213 /**
214 * Returns the default backend implementation for backendName. Which one is used, is defined 214 * Returns the default backend implementation for backendName. Which one is used, is defined
215 * by the configfile "pimaccess.conf". 215 * by the configfile "pimaccess.conf".
216 * @param type The type of the backend (@see OPimGlobal()) 216 * @param type The type of the backend (@see OPimGlobal())
217 * @param appName The name of your application. It will be passed on to the backend 217 * @param appName The name of your application. It will be passed on to the backend
218 * @see OPimGlobal() 218 * @see OPimGlobal()
219 */ 219 */
220 static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ 220 static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){
221 return create( type, OPimGlobal::DEFAULT, appName ); 221 return create( type, OPimGlobal::DEFAULT, appName );
222 } 222 }
223 private: 223 private:
224 OBackendPrivate* d; 224 OBackendPrivate* d;
225 225
226}; 226 };
227 227
228} 228}
229 229
230#endif 230#endif
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 7a3d7cb..2602493 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -58,40 +58,40 @@
58#include <fcntl.h> 58#include <fcntl.h>
59#include <unistd.h> 59#include <unistd.h>
60#include <stdlib.h> 60#include <stdlib.h>
61 61
62 62
63namespace Opie { 63namespace Opie {
64 64
65OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 65OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
66 OPimContactAccessBackend* end, bool autosync ): 66 OPimContactAccessBackend* end, bool autosync ):
67 OPimAccessTemplate<OPimContact>( end ) 67 OPimAccessTemplate<OPimContact>( end )
68{ 68{
69 /* take care of the backend. If there is no one defined, we 69 /* take care of the backend. If there is no one defined, we
70 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 70 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
71 */ 71 */
72 if( end == 0 ) { 72 if( end == 0 ) {
73 owarn << "Using BackendFactory !" << oendl; 73 owarn << "Using BackendFactory !" << oendl;
74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); 74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
75 } 75 }
76 // Set backend locally and in template 76 // Set backend locally and in template
77 m_backEnd = end; 77 m_backEnd = end;
78 OPimAccessTemplate<OPimContact>::setBackEnd (end); 78 OPimAccessTemplate<OPimContact>::setBackEnd (end);
79 79
80 80
81 /* Connect signal of external db change to function */ 81 /* Connect signal of external db change to function */
82 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 82 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
83 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), 83 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
84 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 84 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
85 if ( autosync ){ 85 if ( autosync ){
86 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 86 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
87 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), 87 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
88 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 88 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
89 } 89 }
90 90
91 91
92} 92}
93OPimContactAccess::~OPimContactAccess () 93OPimContactAccess::~OPimContactAccess ()
94{ 94{
95 /* The user may forget to save the changed database, therefore try to 95 /* The user may forget to save the changed database, therefore try to
96 * do it for him.. 96 * do it for him..
97 */ 97 */