author | ulf69 <ulf69> | 2004-06-29 05:03:25 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-06-29 05:03:25 (UTC) |
commit | 0538ac1cc17ad4249d27d686b4bc7e80663f475f (patch) (unidiff) | |
tree | abf571d0e2640bbb7ce14818a376ad980492ea05 /kabc/stdaddressbook.cpp | |
parent | 61ef87224517601f8754dd9da1b521a7b0094558 (diff) | |
download | kdepimpi-0538ac1cc17ad4249d27d686b4bc7e80663f475f.zip kdepimpi-0538ac1cc17ad4249d27d686b4bc7e80663f475f.tar.gz kdepimpi-0538ac1cc17ad4249d27d686b4bc7e80663f475f.tar.bz2 |
*** empty log message ***
-rw-r--r-- | kabc/stdaddressbook.cpp | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index f9fc70b..8faaaef 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -1,249 +1,233 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | #ifndef DESKTOP_VERSION | ||
28 | #include <qpe/global.h> | ||
29 | #else | ||
30 | |||
31 | #include <qdir.h> | ||
32 | #endif | ||
33 | #ifdef KAB_EMBEDDED | ||
34 | 27 | ||
28 | /*US | ||
35 | #include <stdlib.h> | 29 | #include <stdlib.h> |
36 | #else //KAB_EMBEDDED | ||
37 | 30 | ||
38 | #include <stdlib.h> | ||
39 | |||
40 | //US#include <kresources/manager.h> | ||
41 | #include <kapplication.h> | 31 | #include <kapplication.h> |
42 | #include <kcrash.h> | 32 | #include <kcrash.h> |
43 | #include <ksimpleconfig.h> | 33 | #include <ksimpleconfig.h> |
44 | 34 | */ | |
45 | |||
46 | #endif //KAB_EMBEDDED | ||
47 | 35 | ||
48 | #include "resource.h" | 36 | #include "resource.h" |
49 | #include <kresources/manager.h> | 37 | #include <kresources/manager.h> |
50 | #include <kdebug.h> | 38 | #include <kdebug.h> |
51 | #include <klocale.h> | 39 | #include <klocale.h> |
52 | #include <kstaticdeleter.h> | 40 | #include <kstaticdeleter.h> |
53 | #include <kstandarddirs.h> | 41 | #include <kstandarddirs.h> |
54 | 42 | ||
55 | #include "stdaddressbook.h" | 43 | #include "stdaddressbook.h" |
56 | 44 | ||
57 | using namespace KABC; | 45 | using namespace KABC; |
58 | 46 | ||
59 | StdAddressBook *StdAddressBook::mSelf = 0; | 47 | StdAddressBook *StdAddressBook::mSelf = 0; |
60 | bool StdAddressBook::mAutomaticSave = true; | 48 | bool StdAddressBook::mAutomaticSave = true; |
61 | 49 | ||
62 | static KStaticDeleter<StdAddressBook> addressBookDeleter; | 50 | static KStaticDeleter<StdAddressBook> addressBookDeleter; |
63 | 51 | ||
64 | QString StdAddressBook::fileName() | 52 | QString StdAddressBook::fileName() |
65 | { | 53 | { |
66 | return locateLocal( "data", "kabc/std.vcf" ); | 54 | return locateLocal( "data", "kabc/std.vcf" ); |
67 | } | 55 | } |
68 | 56 | ||
69 | QString StdAddressBook::directoryName() | 57 | QString StdAddressBook::directoryName() |
70 | { | 58 | { |
71 | qDebug("StdAddressBook::directoryName() WILL FAIL OR NOT" ); | ||
72 | return locateLocal( "data", "kabc/stdvcf" ); | 59 | return locateLocal( "data", "kabc/stdvcf" ); |
73 | } | 60 | } |
74 | 61 | ||
75 | void StdAddressBook::handleCrash() | 62 | void StdAddressBook::handleCrash() |
76 | { | 63 | { |
77 | StdAddressBook::self()->cleanUp(); | 64 | StdAddressBook::self()->cleanUp(); |
78 | } | 65 | } |
79 | 66 | ||
80 | StdAddressBook *StdAddressBook::self() | 67 | StdAddressBook *StdAddressBook::self() |
81 | { | 68 | { |
82 | 69 | ||
83 | if ( !mSelf ) | 70 | if ( !mSelf ) |
84 | { | 71 | { |
85 | QString appdir = StdAddressBook::setTempAppDir(); | 72 | QString appdir = StdAddressBook::setTempAppDir(); |
86 | 73 | ||
87 | kdDebug(5700) << "StdAddressBook::self()" << endl; | 74 | kdDebug(5700) << "StdAddressBook::self()" << endl; |
88 | // US im am not sure why I have to use the other format here?? | 75 | // US im am not sure why I have to use the other format here?? |
89 | #ifdef KAB_EMBEDDED | 76 | #ifdef KAB_EMBEDDED |
90 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); | 77 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); |
91 | #else //KAB_EMBEDDED | 78 | #else //KAB_EMBEDDED |
92 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); | 79 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); |
93 | #endif //KAB_EMBEDDED | 80 | #endif //KAB_EMBEDDED |
94 | KStandardDirs::setAppDir( appdir ); | 81 | KStandardDirs::setAppDir( appdir ); |
95 | } | 82 | } |
96 | 83 | ||
97 | return mSelf; | 84 | return mSelf; |
98 | } | 85 | } |
99 | 86 | ||
100 | QString StdAddressBook::setTempAppDir() | 87 | QString StdAddressBook::setTempAppDir() |
101 | { | 88 | { |
102 | QString appDIR = KStandardDirs::appDir(); | 89 | QString appDIR = KStandardDirs::appDir(); |
103 | #ifdef DESKTOP_VERSION | 90 | #ifdef DESKTOP_VERSION |
104 | QString appdir = QDir::homeDirPath(); | 91 | QString appdir = QDir::homeDirPath(); |
105 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) | 92 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) |
106 | appdir += "kaddressbook/"; | 93 | appdir += "kaddressbook/"; |
107 | else | 94 | else |
108 | appdir += "/kaddressbook/"; | 95 | appdir += "/kaddressbook/"; |
109 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); | 96 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); |
110 | #else | 97 | #else |
111 | KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) ); | 98 | KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) ); |
112 | #endif | 99 | #endif |
113 | 100 | ||
114 | return appDIR; | 101 | return appDIR; |
115 | } | 102 | } |
116 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) | 103 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) |
117 | { | 104 | { |
118 | 105 | ||
119 | if ( !mSelf ) | 106 | if ( !mSelf ) |
120 | { | 107 | { |
121 | QString appdir =StdAddressBook::setTempAppDir(); | 108 | QString appdir =StdAddressBook::setTempAppDir(); |
122 | #ifdef KAB_EMBEDDED | 109 | #ifdef KAB_EMBEDDED |
123 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); | 110 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); |
124 | #else //KAB_EMBEDDED | 111 | #else //KAB_EMBEDDED |
125 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); | 112 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); |
126 | #endif //KAB_EMBEDDED | 113 | #endif //KAB_EMBEDDED |
127 | KStandardDirs::setAppDir( appdir ); | 114 | KStandardDirs::setAppDir( appdir ); |
128 | } | 115 | } |
129 | return mSelf; | 116 | return mSelf; |
130 | } | 117 | } |
131 | 118 | ||
132 | StdAddressBook::StdAddressBook() | 119 | StdAddressBook::StdAddressBook() |
133 | //US : AddressBook( "kabcrc" ) | 120 | //US : AddressBook( "kabcrc" ) |
134 | : AddressBook( locateLocal( "config", "kabcrc") ) | 121 | : AddressBook( locateLocal( "config", "kabcrc") ) |
135 | { | 122 | { |
136 | 123 | ||
137 | init( false ); | 124 | init( false ); |
138 | } | 125 | } |
139 | 126 | ||
140 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 127 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
141 | //US : AddressBook( "kabcrc" ) | 128 | //US : AddressBook( "kabcrc" ) |
142 | : AddressBook( locateLocal( "config", "kabcrc") ) | 129 | : AddressBook( locateLocal( "config", "kabcrc") ) |
143 | { | 130 | { |
144 | 131 | ||
145 | init( onlyFastResources ); | 132 | init( onlyFastResources ); |
146 | } | 133 | } |
147 | 134 | ||
148 | StdAddressBook::~StdAddressBook() | 135 | StdAddressBook::~StdAddressBook() |
149 | { | 136 | { |
150 | if ( mAutomaticSave ) | 137 | if ( mAutomaticSave ) |
151 | save(); | 138 | save(); |
152 | } | 139 | } |
153 | 140 | ||
154 | void StdAddressBook::init( bool ) | 141 | void StdAddressBook::init( bool ) |
155 | { | 142 | { |
156 | KRES::Manager<Resource> *manager = resourceManager(); | 143 | KRES::Manager<Resource> *manager = resourceManager(); |
157 | KRES::Manager<Resource>::ActiveIterator it; | 144 | KRES::Manager<Resource>::ActiveIterator it; |
158 | 145 | ||
159 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 146 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
160 | (*it)->setAddressBook( this ); | 147 | (*it)->setAddressBook( this ); |
161 | if ( !(*it)->open() ) | 148 | if ( !(*it)->open() ) |
162 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 149 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
163 | } | 150 | } |
164 | 151 | ||
165 | Resource *res = standardResource(); | 152 | Resource *res = standardResource(); |
166 | if ( !res ) { | 153 | if ( !res ) { |
167 | res = manager->createResource( "file" ); | 154 | res = manager->createResource( "file" ); |
168 | if ( res ) | 155 | if ( res ) |
169 | { | 156 | { |
170 | addResource( res ); | 157 | addResource( res ); |
171 | } | 158 | } |
172 | else | 159 | else |
173 | kdDebug(5700) << "No resource available!!!" << endl; | 160 | kdDebug(5700) << "No resource available!!!" << endl; |
174 | } | 161 | } |
175 | 162 | ||
176 | setStandardResource( res ); | 163 | setStandardResource( res ); |
177 | manager->writeConfig(); | 164 | manager->writeConfig(); |
178 | 165 | ||
179 | load(); | 166 | load(); |
180 | } | 167 | } |
181 | 168 | ||
182 | bool StdAddressBook::save() | 169 | bool StdAddressBook::save() |
183 | { | 170 | { |
184 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 171 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
185 | 172 | ||
186 | bool ok = true; | 173 | bool ok = true; |
187 | AddressBook *ab = self(); | 174 | AddressBook *ab = self(); |
188 | 175 | ||
189 | ab->deleteRemovedAddressees(); | 176 | ab->deleteRemovedAddressees(); |
190 | 177 | ||
191 | KRES::Manager<Resource>::ActiveIterator it; | 178 | KRES::Manager<Resource>::ActiveIterator it; |
192 | KRES::Manager<Resource> *manager = ab->resourceManager(); | 179 | KRES::Manager<Resource> *manager = ab->resourceManager(); |
193 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 180 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
194 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 181 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
195 | Ticket *ticket = ab->requestSaveTicket( *it ); | 182 | Ticket *ticket = ab->requestSaveTicket( *it ); |
196 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 183 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
197 | if ( !ticket ) { | 184 | if ( !ticket ) { |
198 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) | 185 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) |
199 | .arg( (*it)->resourceName() ) ); | 186 | .arg( (*it)->resourceName() ) ); |
200 | return false; | 187 | return false; |
201 | } | 188 | } |
202 | 189 | ||
203 | if ( !ab->save( ticket ) ) | 190 | if ( !ab->save( ticket ) ) |
204 | ok = false; | 191 | ok = false; |
205 | } | 192 | } |
206 | } | 193 | } |
207 | 194 | ||
208 | return ok; | 195 | return ok; |
209 | } | 196 | } |
210 | 197 | ||
211 | void StdAddressBook::close() | 198 | void StdAddressBook::close() |
212 | { | 199 | { |
213 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? | 200 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? |
214 | #ifndef KAB_EMBEDDED | 201 | //US addressBookDeleter.destructObject(); |
215 | addressBookDeleter.destructObject(); | ||
216 | #else //KAB_EMBEDDED | ||
217 | addressBookDeleter.setObject(0); | 202 | addressBookDeleter.setObject(0); |
218 | #endif //KAB_EMBEDDED | ||
219 | 203 | ||
220 | } | 204 | } |
221 | 205 | ||
222 | void StdAddressBook::setAutomaticSave( bool enable ) | 206 | void StdAddressBook::setAutomaticSave( bool enable ) |
223 | { | 207 | { |
224 | mAutomaticSave = enable; | 208 | mAutomaticSave = enable; |
225 | } | 209 | } |
226 | 210 | ||
227 | bool StdAddressBook::automaticSave() | 211 | bool StdAddressBook::automaticSave() |
228 | { | 212 | { |
229 | return mAutomaticSave; | 213 | return mAutomaticSave; |
230 | } | 214 | } |
231 | 215 | ||
232 | // should get const for 4.X | 216 | // should get const for 4.X |
233 | Addressee StdAddressBook::whoAmI() | 217 | Addressee StdAddressBook::whoAmI() |
234 | { | 218 | { |
235 | //US KConfig config( "kabcrc" ); | 219 | //US KConfig config( "kabcrc" ); |
236 | KConfig config( locateLocal("config", "kabcrc") ); | 220 | KConfig config( locateLocal("config", "kabcrc") ); |
237 | config.setGroup( "General" ); | 221 | config.setGroup( "General" ); |
238 | 222 | ||
239 | return findByUid( config.readEntry( "WhoAmI" ) ); | 223 | return findByUid( config.readEntry( "WhoAmI" ) ); |
240 | } | 224 | } |
241 | 225 | ||
242 | void StdAddressBook::setWhoAmI( const Addressee &addr ) | 226 | void StdAddressBook::setWhoAmI( const Addressee &addr ) |
243 | { | 227 | { |
244 | //US KConfig config( "kabcrc" ); | 228 | //US KConfig config( "kabcrc" ); |
245 | KConfig config( locateLocal("config", "kabcrc") ); | 229 | KConfig config( locateLocal("config", "kabcrc") ); |
246 | config.setGroup( "General" ); | 230 | config.setGroup( "General" ); |
247 | 231 | ||
248 | config.writeEntry( "WhoAmI", addr.uid() ); | 232 | config.writeEntry( "WhoAmI", addr.uid() ); |
249 | } | 233 | } |