-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 276 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 38 |
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 | |||
@@ -1,230 +1,230 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | 3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * ===================================================================== | 30 | * ===================================================================== |
31 | * ToDo: Use plugins | 31 | * ToDo: Use plugins |
32 | * ===================================================================== | 32 | * ===================================================================== |
33 | */ | 33 | */ |
34 | #ifndef OPIE_BACKENDFACTORY_H_ | 34 | #ifndef OPIE_BACKENDFACTORY_H_ |
35 | #define OPIE_BACKENDFACTORY_H_ | 35 | #define OPIE_BACKENDFACTORY_H_ |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | #include <opie2/opimaccessbackend.h> | 38 | #include <opie2/opimaccessbackend.h> |
39 | #include <opie2/opimglobal.h> | 39 | #include <opie2/opimglobal.h> |
40 | #include <opie2/otodoaccessxml.h> | 40 | #include <opie2/otodoaccessxml.h> |
41 | #include <opie2/otodoaccessvcal.h> | 41 | #include <opie2/otodoaccessvcal.h> |
42 | #include <opie2/ocontactaccessbackend_xml.h> | 42 | #include <opie2/ocontactaccessbackend_xml.h> |
43 | #include <opie2/ocontactaccessbackend_vcard.h> | 43 | #include <opie2/ocontactaccessbackend_vcard.h> |
44 | #include <opie2/odatebookaccessbackend_xml.h> | 44 | #include <opie2/odatebookaccessbackend_xml.h> |
45 | #include <opie2/odebug.h> | 45 | #include <opie2/odebug.h> |
46 | 46 | ||
47 | #ifdef __USE_SQL | 47 | #ifdef __USE_SQL |
48 | #include <opie2/otodoaccesssql.h> | 48 | #include <opie2/otodoaccesssql.h> |
49 | #include <opie2/ocontactaccessbackend_sql.h> | 49 | #include <opie2/ocontactaccessbackend_sql.h> |
50 | #include <opie2/odatebookaccessbackend_sql.h> | 50 | #include <opie2/odatebookaccessbackend_sql.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #include <qpe/config.h> | 53 | #include <qpe/config.h> |
54 | 54 | ||
55 | /* QT */ | 55 | /* QT */ |
56 | #include <qstring.h> | 56 | #include <qstring.h> |
57 | #include <qasciidict.h> | 57 | #include <qasciidict.h> |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | using namespace Opie::Pim; | 62 | using namespace Opie::Pim; |
63 | 63 | ||
64 | namespace Opie { | 64 | namespace Opie { |
65 | 65 | ||
66 | class OBackendPrivate; | 66 | class 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 | */ |
83 | template<class T> | 83 | template<class T> |
84 | class 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 | |||
@@ -1,164 +1,164 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * ===================================================================== | 30 | * ===================================================================== |
31 | * ToDo: XML-Backend: Automatic reload if something was changed... | 31 | * ToDo: XML-Backend: Automatic reload if something was changed... |
32 | * | 32 | * |
33 | * | 33 | * |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "ocontactaccess.h" | 36 | #include "ocontactaccess.h" |
37 | #include "obackendfactory.h" | 37 | #include "obackendfactory.h" |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | #include <opie2/ocontactaccessbackend_xml.h> | 40 | #include <opie2/ocontactaccessbackend_xml.h> |
41 | #include <opie2/opimresolver.h> | 41 | #include <opie2/opimresolver.h> |
42 | #include <opie2/opimglobal.h> | 42 | #include <opie2/opimglobal.h> |
43 | #include <opie2/odebug.h> | 43 | #include <opie2/odebug.h> |
44 | 44 | ||
45 | //#include <qpe/qcopenvelope_qws.h> | 45 | //#include <qpe/qcopenvelope_qws.h> |
46 | #include <qpe/global.h> | 46 | #include <qpe/global.h> |
47 | 47 | ||
48 | /* QT */ | 48 | /* QT */ |
49 | #include <qasciidict.h> | 49 | #include <qasciidict.h> |
50 | #include <qdatetime.h> | 50 | #include <qdatetime.h> |
51 | #include <qfile.h> | 51 | #include <qfile.h> |
52 | #include <qregexp.h> | 52 | #include <qregexp.h> |
53 | #include <qlist.h> | 53 | #include <qlist.h> |
54 | #include <qcopchannel_qws.h> | 54 | #include <qcopchannel_qws.h> |
55 | 55 | ||
56 | /* STD */ | 56 | /* STD */ |
57 | #include <errno.h> | 57 | #include <errno.h> |
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 | ||
63 | namespace Opie { | 63 | namespace Opie { |
64 | 64 | ||
65 | OPimContactAccess::OPimContactAccess ( const QString appname, const QString , | 65 | OPimContactAccess::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 | } |
93 | OPimContactAccess::~OPimContactAccess () | 93 | OPimContactAccess::~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 | */ |
98 | save(); | 98 | save(); |
99 | // delete m_backEnd; is done by template.. | 99 | // delete m_backEnd; is done by template.. |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | bool OPimContactAccess::save () | 103 | bool OPimContactAccess::save () |
104 | { | 104 | { |
105 | /* If the database was changed externally, we could not save the | 105 | /* If the database was changed externally, we could not save the |
106 | * Data. This will remove added items which is unacceptable ! | 106 | * Data. This will remove added items which is unacceptable ! |
107 | * Therefore: Reload database and merge the data... | 107 | * Therefore: Reload database and merge the data... |
108 | */ | 108 | */ |
109 | if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) | 109 | if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) |
110 | reload(); | 110 | reload(); |
111 | 111 | ||
112 | bool status = OPimAccessTemplate<OPimContact>::save(); | 112 | bool status = OPimAccessTemplate<OPimContact>::save(); |
113 | if ( !status ) return false; | 113 | if ( !status ) return false; |
114 | 114 | ||
115 | /* Now tell everyone that new data is available. | 115 | /* Now tell everyone that new data is available. |
116 | */ | 116 | */ |
117 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 117 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
118 | 118 | ||
119 | return true; | 119 | return true; |
120 | } | 120 | } |
121 | 121 | ||
122 | const uint OPimContactAccess::querySettings() | 122 | const uint OPimContactAccess::querySettings() |
123 | { | 123 | { |
124 | return ( m_backEnd->querySettings() ); | 124 | return ( m_backEnd->querySettings() ); |
125 | } | 125 | } |
126 | 126 | ||
127 | bool OPimContactAccess::hasQuerySettings ( int querySettings ) const | 127 | bool OPimContactAccess::hasQuerySettings ( int querySettings ) const |
128 | { | 128 | { |
129 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 129 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
130 | } | 130 | } |
131 | OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | 131 | OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const |
132 | { | 132 | { |
133 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | 133 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); |
134 | return ( OPimRecordList<OPimContact>(matchingContacts, this) ); | 134 | return ( OPimRecordList<OPimContact>(matchingContacts, this) ); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | bool OPimContactAccess::wasChangedExternally()const | 138 | bool OPimContactAccess::wasChangedExternally()const |
139 | { | 139 | { |
140 | return ( m_backEnd->wasChangedExternally() ); | 140 | return ( m_backEnd->wasChangedExternally() ); |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 144 | void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
145 | { | 145 | { |
146 | if ( msg == "addressbookUpdated()" ){ | 146 | if ( msg == "addressbookUpdated()" ){ |
147 | owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl; | 147 | owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl; |
148 | emit signalChanged ( this ); | 148 | emit signalChanged ( this ); |
149 | } else if ( msg == "flush()" ) { | 149 | } else if ( msg == "flush()" ) { |
150 | owarn << "OPimContactAccess: Received flush()" << oendl; | 150 | owarn << "OPimContactAccess: Received flush()" << oendl; |
151 | save (); | 151 | save (); |
152 | } else if ( msg == "reload()" ) { | 152 | } else if ( msg == "reload()" ) { |
153 | owarn << "OPimContactAccess: Received reload()" << oendl; | 153 | owarn << "OPimContactAccess: Received reload()" << oendl; |
154 | reload (); | 154 | reload (); |
155 | emit signalChanged ( this ); | 155 | emit signalChanged ( this ); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | int OPimContactAccess::rtti() const | 159 | int OPimContactAccess::rtti() const |
160 | { | 160 | { |
161 | return OPimResolver::AddressBook; | 161 | return OPimResolver::AddressBook; |
162 | } | 162 | } |
163 | 163 | ||
164 | } | 164 | } |