Diffstat (limited to 'libopie2/opiepim/core/opimresolver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimresolver.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp index 4ebbd6e..eceabcb 100644 --- a/libopie2/opiepim/core/opimresolver.cpp +++ b/libopie2/opiepim/core/opimresolver.cpp | |||
@@ -1,57 +1,87 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qcopchannel_qws.h> | 29 | #include <qcopchannel_qws.h> |
2 | 30 | ||
3 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
4 | 32 | ||
5 | #include "otodoaccess.h" | 33 | #include <opie2/otodoaccess.h> |
6 | #include "ocontactaccess.h" | 34 | #include <opie2/ocontactaccess.h> |
7 | 35 | ||
8 | //#include "opimfactory.h" | 36 | //#include "opimfactory.h" |
9 | #include "opimresolver.h" | 37 | #include <opie2/opimresolver.h> |
38 | |||
39 | namespace Opie { | ||
10 | 40 | ||
11 | OPimResolver* OPimResolver::m_self = 0l; | 41 | OPimResolver* OPimResolver::m_self = 0l; |
12 | 42 | ||
13 | OPimResolver::OPimResolver() { | 43 | OPimResolver::OPimResolver() { |
14 | /* the built in channels */ | 44 | /* the built in channels */ |
15 | m_builtIns << "Todolist" << "Addressbook" << "Datebook"; | 45 | m_builtIns << "Todolist" << "Addressbook" << "Datebook"; |
16 | } | 46 | } |
17 | OPimResolver* OPimResolver::self() { | 47 | OPimResolver* OPimResolver::self() { |
18 | if (!m_self) | 48 | if (!m_self) |
19 | m_self = new OPimResolver(); | 49 | m_self = new OPimResolver(); |
20 | 50 | ||
21 | return m_self; | 51 | return m_self; |
22 | } | 52 | } |
23 | 53 | ||
24 | /* | 54 | /* |
25 | * FIXME use a cache here too | 55 | * FIXME use a cache here too |
26 | */ | 56 | */ |
27 | OPimRecord* OPimResolver::record( const QString& service, int uid ) { | 57 | OPimRecord* OPimResolver::record( const QString& service, int uid ) { |
28 | OPimRecord* rec = 0l; | 58 | OPimRecord* rec = 0l; |
29 | OPimBase* base = backend( service ); | 59 | OPimBase* base = backend( service ); |
30 | 60 | ||
31 | if ( base ) | 61 | if ( base ) |
32 | rec = base->record( uid ); | 62 | rec = base->record( uid ); |
33 | delete base; | 63 | delete base; |
34 | 64 | ||
35 | return rec; | 65 | return rec; |
36 | } | 66 | } |
37 | OPimRecord* OPimResolver::record( const QString& service ) { | 67 | OPimRecord* OPimResolver::record( const QString& service ) { |
38 | return record( serviceId( service ) ); | 68 | return record( serviceId( service ) ); |
39 | } | 69 | } |
40 | OPimRecord* OPimResolver::record( int rtti ) { | 70 | OPimRecord* OPimResolver::record( int rtti ) { |
41 | OPimRecord* rec = 0l; | 71 | OPimRecord* rec = 0l; |
42 | switch( rtti ) { | 72 | switch( rtti ) { |
43 | case 1: /* todolist */ | 73 | case 1: /* todolist */ |
44 | rec = new OTodo(); | 74 | rec = new OTodo(); |
45 | case 2: /* contact */ | 75 | case 2: /* contact */ |
46 | rec = new OContact(); | 76 | rec = new OContact(); |
47 | default: | 77 | default: |
48 | break; | 78 | break; |
49 | } | 79 | } |
50 | /* | 80 | /* |
51 | * FIXME resolve externally | 81 | * FIXME resolve externally |
52 | */ | 82 | */ |
53 | if (!rec ) { | 83 | if (!rec ) { |
54 | ; | 84 | ; |
55 | } | 85 | } |
56 | return 0l; | 86 | return 0l; |
57 | } | 87 | } |
@@ -151,48 +181,50 @@ int OPimResolver::serviceId( const QString& service ) { | |||
151 | /** | 181 | /** |
152 | * check if the 'service' is registered and if so we'll | 182 | * check if the 'service' is registered and if so we'll |
153 | */ | 183 | */ |
154 | bool OPimResolver::add( const QString& service, const OPimRecord& rec) { | 184 | bool OPimResolver::add( const QString& service, const OPimRecord& rec) { |
155 | if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) { | 185 | if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) { |
156 | QByteArray data; | 186 | QByteArray data; |
157 | QDataStream arg(data, IO_WriteOnly ); | 187 | QDataStream arg(data, IO_WriteOnly ); |
158 | if ( rec.saveToStream( arg ) ) { | 188 | if ( rec.saveToStream( arg ) ) { |
159 | QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" ); | 189 | QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" ); |
160 | env << rec.rtti(); | 190 | env << rec.rtti(); |
161 | env << data; | 191 | env << data; |
162 | }else | 192 | }else |
163 | return false; | 193 | return false; |
164 | }else{ | 194 | }else{ |
165 | OPimBase* base = backend( service ); | 195 | OPimBase* base = backend( service ); |
166 | if (!base ) return false; | 196 | if (!base ) return false; |
167 | 197 | ||
168 | base->load(); | 198 | base->load(); |
169 | base->add( rec ); | 199 | base->add( rec ); |
170 | base->save(); | 200 | base->save(); |
171 | delete base; | 201 | delete base; |
172 | } | 202 | } |
173 | 203 | ||
174 | return true; | 204 | return true; |
175 | } | 205 | } |
176 | OPimBase* OPimResolver::backend( const QString& service ) { | 206 | OPimBase* OPimResolver::backend( const QString& service ) { |
177 | return backend( serviceId( service ) ); | 207 | return backend( serviceId( service ) ); |
178 | } | 208 | } |
179 | OPimBase* OPimResolver::backend( int rtti ) { | 209 | OPimBase* OPimResolver::backend( int rtti ) { |
180 | OPimBase* base = 0l; | 210 | OPimBase* base = 0l; |
181 | switch( rtti ) { | 211 | switch( rtti ) { |
182 | case TodoList: | 212 | case TodoList: |
183 | base = new OTodoAccess(); | 213 | base = new OTodoAccess(); |
184 | break; | 214 | break; |
185 | case DateBook: | 215 | case DateBook: |
186 | break; | 216 | break; |
187 | case AddressBook: | 217 | case AddressBook: |
188 | base = new OContactAccess("Resolver"); | 218 | base = new OContactAccess("Resolver"); |
189 | break; | 219 | break; |
190 | default: | 220 | default: |
191 | break; | 221 | break; |
192 | } | 222 | } |
193 | // FIXME for 3rd party | 223 | // FIXME for 3rd party |
194 | if (!base ) | 224 | if (!base ) |
195 | ; | 225 | ; |
196 | 226 | ||
197 | return base; | 227 | return base; |
198 | } | 228 | } |
229 | |||
230 | } | ||