author | eilers <eilers> | 2004-05-16 16:03:30 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-05-16 16:03:30 (UTC) |
commit | 52691aca593d6b321597d26467b9e9af9ec0b6fe (patch) (unidiff) | |
tree | de3091da50aed7ed265f3f50f884dc7bbfa84f2b | |
parent | 680c8c7a6db8f5b79a6541629f54465709b79b02 (diff) | |
download | opie-52691aca593d6b321597d26467b9e9af9ec0b6fe.zip opie-52691aca593d6b321597d26467b9e9af9ec0b6fe.tar.gz opie-52691aca593d6b321597d26467b9e9af9ec0b6fe.tar.bz2 |
Backendfactory allows to request the default database style which is defined
by Settings/pimaccess.conf.
This will be used by the OPimAccessFactory .. see next commit..
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 61 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimglobal.h | 2 |
2 files changed, 46 insertions, 17 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index d101373..d8caa80 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -78,7 +78,7 @@ class OBackendFactory | |||
78 | OBackendFactory() {}; | 78 | OBackendFactory() {}; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Returns a 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. |
@@ -125,6 +125,43 @@ class OBackendFactory | |||
125 | 125 | ||
126 | } | 126 | } |
127 | 127 | ||
128 | |||
129 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType backend ){ | ||
130 | QString group_name; | ||
131 | switch ( backend ){ | ||
132 | case OPimGlobal::TODOLIST: | ||
133 | group_name = "todo"; | ||
134 | break; | ||
135 | case OPimGlobal::CONTACTLIST: | ||
136 | group_name = "contact"; | ||
137 | break; | ||
138 | case OPimGlobal::DATEBOOK: | ||
139 | group_name = "datebook"; | ||
140 | break; | ||
141 | default: | ||
142 | group_name = "unknown"; | ||
143 | } | ||
144 | |||
145 | Config config( "pimaccess" ); | ||
146 | config.setGroup ( group_name ); | ||
147 | QString db_String = config.readEntry( "usebackend" ); | ||
148 | |||
149 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | ||
150 | dictDbTypes.setAutoDelete( TRUE ); | ||
151 | |||
152 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | ||
153 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | ||
154 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | ||
155 | |||
156 | int* db_find = dictDbTypes[ db_String ]; | ||
157 | |||
158 | if ( !db_find ) | ||
159 | return OPimGlobal::UNKNOWN; | ||
160 | |||
161 | return (OPimGlobal::DatabaseStyle) *db_find; | ||
162 | } | ||
163 | |||
164 | |||
128 | /** | 165 | /** |
129 | * Returns the default backend implementation for backendName. Which one is used, is defined | 166 | * Returns the default backend implementation for backendName. Which one is used, is defined |
130 | * by the configfile "pimaccess.conf". | 167 | * by the configfile "pimaccess.conf". |
@@ -140,25 +177,15 @@ class OBackendFactory | |||
140 | dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); | 177 | dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); |
141 | dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); | 178 | dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); |
142 | 179 | ||
143 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | ||
144 | dictDbTypes.setAutoDelete( TRUE ); | ||
145 | |||
146 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | ||
147 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | ||
148 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | ||
149 | |||
150 | Config config( "pimaccess" ); | ||
151 | config.setGroup ( backendName ); | ||
152 | QString db_String = config.readEntry( "usebackend" ); | ||
153 | |||
154 | int* db_find = dictDbTypes[ db_String ]; | ||
155 | int* backend_find = dictBackends[ backendName ]; | 180 | int* backend_find = dictBackends[ backendName ]; |
156 | if ( !backend_find || !db_find ) return NULL; | 181 | if ( !backend_find ) return NULL; |
182 | |||
183 | OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) ); | ||
157 | 184 | ||
158 | qDebug( "OBackendFactory::Default -> Backend is %s, Database is %s", backendName.latin1(), | 185 | qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(), |
159 | db_String.latin1() ); | 186 | style ); |
160 | 187 | ||
161 | return create( (OPimGlobal::PimType) *backend_find, (OPimGlobal::DatabaseStyle) *db_find, appName ); | 188 | return create( (OPimGlobal::PimType) *backend_find, style, appName ); |
162 | 189 | ||
163 | } | 190 | } |
164 | private: | 191 | private: |
diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h index 2d336b4..d56c9be 100644 --- a/libopie2/opiepim/core/opimglobal.h +++ b/libopie2/opiepim/core/opimglobal.h | |||
@@ -46,6 +46,8 @@ class OPimGlobal{ | |||
46 | }; | 46 | }; |
47 | 47 | ||
48 | enum DatabaseStyle { | 48 | enum DatabaseStyle { |
49 | DEFAULT, // Use default Database | ||
50 | UNKNOWN, // Unknown database style | ||
49 | XML, | 51 | XML, |
50 | SQL, | 52 | SQL, |
51 | VCARD, | 53 | VCARD, |