summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 4daf861..4bedbef 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -62,57 +62,57 @@ class OBackendPrivate;
62 * allow users to switch the backend with ( XML->SQLite ) without the need 62 * allow users to switch the backend with ( XML->SQLite ) without the need
63 * to recompile.# 63 * to recompile.#
64 * This class - as the whole PIM Api - is making use of templates 64 * This class - as the whole PIM Api - is making use of templates
65 * 65 *
66 * <pre> 66 * <pre>
67 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null ); 67 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null );
68 * backend->load(); 68 * backend->load();
69 * </pre> 69 * </pre>
70 * 70 *
71 * @author Stefan Eilers 71 * @author Stefan Eilers
72 * @version 0.1 72 * @version 0.1
73 */ 73 */
74template<class T> 74template<class T>
75class OBackendFactory 75class OBackendFactory
76{ 76{
77 public: 77 public:
78 OBackendFactory() {}; 78 OBackendFactory() {};
79 79
80 /** 80 /**
81 * Returns a selected backend implementation 81 * Returns a selected backend implementation
82 * @param type the type of the backend 82 * @param type the type of the backend
83 * @param database the type of the used database 83 * @param database the type of the used database
84 * @param appName The name of your application. It will be passed on to the backend. 84 * @param appName The name of your application. It will be passed on to the backend.
85 */ 85 */
86 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, 86 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
87 const QString& appName ){ 87 const QString& appName ){
88 qWarning("Selected backend for %d is: %d", type, database ); 88 qWarning("Selected backend for %d is: %d", type, database );
89 // If we should use the dafult database style, we have to request it 89 // If we should use the dafult database style, we have to request it
90 OPimGlobal::DatabaseStyle used_database = database; 90 OPimGlobal::DatabaseStyle used_database = database;
91 if ( database == OPimGlobal::DEFAULT ){ 91 if ( database == OPimGlobal::DEFAULT ){
92 used_database = defaultDB( type ); 92 used_database = defaultDB( type );
93 } 93 }
94 94
95 95
96 switch ( type ){ 96 switch ( type ){
97 case OPimGlobal::TODOLIST: 97 case OPimGlobal::TODOLIST:
98#ifdef __USE_SQL 98#ifdef __USE_SQL
99 if ( used_database == OPimGlobal::SQL ) 99 if ( used_database == OPimGlobal::SQL )
100 return (T*) new OPimTodoAccessBackendSQL(""); 100 return (T*) new OPimTodoAccessBackendSQL("");
101#else 101#else
102 if ( used_database == OPimGlobal::SQL ) 102 if ( used_database == OPimGlobal::SQL )
103 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); 103 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!");
104#endif 104#endif
105 105
106 return (T*) new OPimTodoAccessXML( appName ); 106 return (T*) new OPimTodoAccessXML( appName );
107 case OPimGlobal::CONTACTLIST: 107 case OPimGlobal::CONTACTLIST:
108#ifdef __USE_SQL 108#ifdef __USE_SQL
109 if ( used_database == OPimGlobal::SQL ) 109 if ( used_database == OPimGlobal::SQL )
110 return (T*) new OPimContactAccessBackend_SQL(""); 110 return (T*) new OPimContactAccessBackend_SQL("");
111#else 111#else
112 if ( used_database == OPimGlobal::SQL ) 112 if ( used_database == OPimGlobal::SQL )
113 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); 113 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!");
114#endif 114#endif
115 115
116 return (T*) new OPimContactAccessBackend_XML( appName ); 116 return (T*) new OPimContactAccessBackend_XML( appName );
117 case OPimGlobal::DATEBOOK: 117 case OPimGlobal::DATEBOOK:
118#ifdef __USE_SQL 118#ifdef __USE_SQL
@@ -133,76 +133,76 @@ class OBackendFactory
133 133
134 /** 134 /**
135 * Returns the style of the default database which is used to contact PIM data. 135 * Returns the style of the default database which is used to contact PIM data.
136 * @param type the type of the backend 136 * @param type the type of the backend
137 * @see OPimGlobal 137 * @see OPimGlobal
138 */ 138 */
139 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ 139 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
140 QString group_name; 140 QString group_name;
141 switch ( type ){ 141 switch ( type ){
142 case OPimGlobal::TODOLIST: 142 case OPimGlobal::TODOLIST:
143 group_name = "todo"; 143 group_name = "todo";
144 break; 144 break;
145 case OPimGlobal::CONTACTLIST: 145 case OPimGlobal::CONTACTLIST:
146 group_name = "contact"; 146 group_name = "contact";
147 break; 147 break;
148 case OPimGlobal::DATEBOOK: 148 case OPimGlobal::DATEBOOK:
149 group_name = "datebook"; 149 group_name = "datebook";
150 break; 150 break;
151 default: 151 default:
152 group_name = "unknown"; 152 group_name = "unknown";
153 } 153 }
154 154
155 Config config( "pimaccess" ); 155 Config config( "pimaccess" );
156 config.setGroup ( group_name ); 156 config.setGroup ( group_name );
157 QString db_String = config.readEntry( "usebackend" ); 157 QString db_String = config.readEntry( "usebackend", "xml" );
158 158
159 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); 159 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
160 dictDbTypes.setAutoDelete( TRUE ); 160 dictDbTypes.setAutoDelete( TRUE );
161 161
162 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); 162 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
163 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); 163 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
164 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); 164 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
165 165
166 int* db_find = dictDbTypes[ db_String ]; 166 int* db_find = dictDbTypes[ db_String ];
167 167
168 if ( !db_find ) 168 if ( !db_find )
169 return OPimGlobal::UNKNOWN; 169 return OPimGlobal::UNKNOWN;
170 170
171 return (OPimGlobal::DatabaseStyle) *db_find; 171 return (OPimGlobal::DatabaseStyle) *db_find;
172 } 172 }
173 173
174 174
175 /** 175 /**
176 * Returns the default backend implementation for backendName. Which one is used, is defined 176 * Returns the default backend implementation for backendName. Which one is used, is defined
177 * by the configfile "pimaccess.conf". 177 * by the configfile "pimaccess.conf".
178 * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) 178 * @param backendName the type of the backend (use "todo", "contact" or "datebook" )
179 * @param appName The name of your application. It will be passed on to the backend 179 * @param appName The name of your application. It will be passed on to the backend
180 */ 180 */
181 static T* defaultBackend( const QString backendName, const QString& appName ){ 181 static T* defaultBackend( const QString backendName, const QString& appName ){
182 182
183 QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType ); 183 QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType );
184 dictBackends.setAutoDelete ( TRUE ); 184 dictBackends.setAutoDelete ( TRUE );
185 185
186 dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); 186 dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) );
187 dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); 187 dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) );
188 dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); 188 dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) );
189 189
190 int* backend_find = dictBackends[ backendName ]; 190 int* backend_find = dictBackends[ backendName ];
191 if ( !backend_find ) return NULL; 191 if ( !backend_find ) return NULL;
192 192
193 OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) ); 193 OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) );
194 194
195 qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(), 195 qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(),
196 style ); 196 style );
197 197
198 return create( (OPimGlobal::PimType) *backend_find, style, appName ); 198 return create( (OPimGlobal::PimType) *backend_find, style, appName );
199 199
200 } 200 }
201 private: 201 private:
202 OBackendPrivate* d; 202 OBackendPrivate* d;
203 203
204}; 204};
205 205
206} 206}
207 207
208#endif 208#endif