author | zautrix <zautrix> | 2004-09-07 22:51:29 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-07 22:51:29 (UTC) |
commit | 2676646d4744ccceab1063dc02d772a26a203c61 (patch) (unidiff) | |
tree | 0a0d5261b9a804a29b61a38f68339979051282e2 /kabc/stdaddressbook.cpp | |
parent | 64a8ef1629f523df3006de5cb2b9882a50d96a05 (diff) | |
download | kdepimpi-2676646d4744ccceab1063dc02d772a26a203c61.zip kdepimpi-2676646d4744ccceab1063dc02d772a26a203c61.tar.gz kdepimpi-2676646d4744ccceab1063dc02d772a26a203c61.tar.bz2 |
Implemented Ompi - kapi connection
-rw-r--r-- | kabc/stdaddressbook.cpp | 12 |
1 files changed, 0 insertions, 12 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index 9f38f08..ec47a4e 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -1,208 +1,196 @@ | |||
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 | 27 | ||
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include "resource.h" | 29 | #include "resource.h" |
30 | #include <kresources/manager.h> | 30 | #include <kresources/manager.h> |
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | #include <kstaticdeleter.h> | 33 | #include <kstaticdeleter.h> |
34 | #include <kstandarddirs.h> | 34 | #include <kstandarddirs.h> |
35 | 35 | ||
36 | #include "stdaddressbook.h" | 36 | #include "stdaddressbook.h" |
37 | 37 | ||
38 | using namespace KABC; | 38 | using namespace KABC; |
39 | 39 | ||
40 | StdAddressBook *StdAddressBook::mSelf = 0; | 40 | StdAddressBook *StdAddressBook::mSelf = 0; |
41 | bool StdAddressBook::mAutomaticSave = true; | 41 | bool StdAddressBook::mAutomaticSave = true; |
42 | 42 | ||
43 | static KStaticDeleter<StdAddressBook> addressBookDeleter; | 43 | static KStaticDeleter<StdAddressBook> addressBookDeleter; |
44 | 44 | ||
45 | QString StdAddressBook::fileName() | 45 | QString StdAddressBook::fileName() |
46 | { | 46 | { |
47 | return locateLocal( "data", "kabc/std.vcf" ); | 47 | return locateLocal( "data", "kabc/std.vcf" ); |
48 | } | 48 | } |
49 | 49 | ||
50 | QString StdAddressBook::directoryName() | 50 | QString StdAddressBook::directoryName() |
51 | { | 51 | { |
52 | return locateLocal( "data", "kabc/stdvcf" ); | 52 | return locateLocal( "data", "kabc/stdvcf" ); |
53 | } | 53 | } |
54 | 54 | ||
55 | void StdAddressBook::handleCrash() | 55 | void StdAddressBook::handleCrash() |
56 | { | 56 | { |
57 | StdAddressBook::self()->cleanUp(); | 57 | StdAddressBook::self()->cleanUp(); |
58 | } | 58 | } |
59 | 59 | ||
60 | StdAddressBook *StdAddressBook::self() | 60 | StdAddressBook *StdAddressBook::self() |
61 | { | 61 | { |
62 | 62 | ||
63 | if ( !mSelf ) | 63 | if ( !mSelf ) |
64 | { | 64 | { |
65 | QString appdir = StdAddressBook::setTempAppDir(); | 65 | QString appdir = StdAddressBook::setTempAppDir(); |
66 | qDebug("****************************************************** "); | ||
67 | qDebug("****************************************************** "); | ||
68 | qDebug("****************************************************** "); | ||
69 | qDebug("****************************************************** "); | ||
70 | qDebug("****************************************************** "); | ||
71 | // US im am not sure why I have to use the other format here?? | 66 | // US im am not sure why I have to use the other format here?? |
72 | #ifdef KAB_EMBEDDED | 67 | #ifdef KAB_EMBEDDED |
73 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); | 68 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); |
74 | #else //KAB_EMBEDDED | 69 | #else //KAB_EMBEDDED |
75 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); | 70 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); |
76 | #endif //KAB_EMBEDDED | 71 | #endif //KAB_EMBEDDED |
77 | KStandardDirs::setAppDir( appdir ); | 72 | KStandardDirs::setAppDir( appdir ); |
78 | } | 73 | } |
79 | 74 | ||
80 | return mSelf; | 75 | return mSelf; |
81 | } | 76 | } |
82 | 77 | ||
83 | QString StdAddressBook::setTempAppDir() | 78 | QString StdAddressBook::setTempAppDir() |
84 | { | 79 | { |
85 | QString appDIR = KStandardDirs::appDir(); | 80 | QString appDIR = KStandardDirs::appDir(); |
86 | #ifdef DESKTOP_VERSION | 81 | #ifdef DESKTOP_VERSION |
87 | QString appdir = QDir::homeDirPath(); | 82 | QString appdir = QDir::homeDirPath(); |
88 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) | 83 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) |
89 | appdir += "kaddressbook/"; | 84 | appdir += "kaddressbook/"; |
90 | else | 85 | else |
91 | appdir += "/kaddressbook/"; | 86 | appdir += "/kaddressbook/"; |
92 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); | 87 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); |
93 | #else | 88 | #else |
94 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; | 89 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; |
95 | 90 | ||
96 | KStandardDirs::setAppDir( appdir ); | 91 | KStandardDirs::setAppDir( appdir ); |
97 | #endif | 92 | #endif |
98 | 93 | ||
99 | return appDIR; | 94 | return appDIR; |
100 | } | 95 | } |
101 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) | 96 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) |
102 | { | 97 | { |
103 | 98 | ||
104 | if ( !mSelf ) | 99 | if ( !mSelf ) |
105 | { | 100 | { |
106 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
107 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
108 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
109 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
110 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
111 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
112 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
113 | QString appdir =StdAddressBook::setTempAppDir(); | 101 | QString appdir =StdAddressBook::setTempAppDir(); |
114 | #ifdef KAB_EMBEDDED | 102 | #ifdef KAB_EMBEDDED |
115 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); | 103 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); |
116 | #else //KAB_EMBEDDED | 104 | #else //KAB_EMBEDDED |
117 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); | 105 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); |
118 | #endif //KAB_EMBEDDED | 106 | #endif //KAB_EMBEDDED |
119 | KStandardDirs::setAppDir( appdir ); | 107 | KStandardDirs::setAppDir( appdir ); |
120 | } | 108 | } |
121 | return mSelf; | 109 | return mSelf; |
122 | } | 110 | } |
123 | 111 | ||
124 | StdAddressBook::StdAddressBook() | 112 | StdAddressBook::StdAddressBook() |
125 | : AddressBook( "kabcrc" ) | 113 | : AddressBook( "kabcrc" ) |
126 | { | 114 | { |
127 | 115 | ||
128 | init( false ); | 116 | init( false ); |
129 | } | 117 | } |
130 | 118 | ||
131 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 119 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
132 | : AddressBook( "kabcrc" ) | 120 | : AddressBook( "kabcrc" ) |
133 | { | 121 | { |
134 | 122 | ||
135 | init( onlyFastResources ); | 123 | init( onlyFastResources ); |
136 | } | 124 | } |
137 | 125 | ||
138 | StdAddressBook::~StdAddressBook() | 126 | StdAddressBook::~StdAddressBook() |
139 | { | 127 | { |
140 | if ( mAutomaticSave ) | 128 | if ( mAutomaticSave ) |
141 | save(); | 129 | save(); |
142 | } | 130 | } |
143 | 131 | ||
144 | void StdAddressBook::init( bool ) | 132 | void StdAddressBook::init( bool ) |
145 | { | 133 | { |
146 | KRES::Manager<Resource> *manager = resourceManager(); | 134 | KRES::Manager<Resource> *manager = resourceManager(); |
147 | KRES::Manager<Resource>::ActiveIterator it; | 135 | KRES::Manager<Resource>::ActiveIterator it; |
148 | 136 | ||
149 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 137 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
150 | (*it)->setAddressBook( this ); | 138 | (*it)->setAddressBook( this ); |
151 | if ( !(*it)->open() ) | 139 | if ( !(*it)->open() ) |
152 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 140 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
153 | } | 141 | } |
154 | 142 | ||
155 | Resource *res = standardResource(); | 143 | Resource *res = standardResource(); |
156 | if ( !res ) { | 144 | if ( !res ) { |
157 | res = manager->createResource( "file" ); | 145 | res = manager->createResource( "file" ); |
158 | if ( res ) | 146 | if ( res ) |
159 | { | 147 | { |
160 | addResource( res ); | 148 | addResource( res ); |
161 | } | 149 | } |
162 | else | 150 | else |
163 | qDebug(" No resource available!!!"); | 151 | qDebug(" No resource available!!!"); |
164 | } | 152 | } |
165 | 153 | ||
166 | setStandardResource( res ); | 154 | setStandardResource( res ); |
167 | manager->writeConfig(); | 155 | manager->writeConfig(); |
168 | 156 | ||
169 | load(); | 157 | load(); |
170 | } | 158 | } |
171 | 159 | ||
172 | bool StdAddressBook::save() | 160 | bool StdAddressBook::save() |
173 | { | 161 | { |
174 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 162 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
175 | 163 | ||
176 | bool ok = true; | 164 | bool ok = true; |
177 | AddressBook *ab = self(); | 165 | AddressBook *ab = self(); |
178 | 166 | ||
179 | ab->deleteRemovedAddressees(); | 167 | ab->deleteRemovedAddressees(); |
180 | 168 | ||
181 | KRES::Manager<Resource>::ActiveIterator it; | 169 | KRES::Manager<Resource>::ActiveIterator it; |
182 | KRES::Manager<Resource> *manager = ab->resourceManager(); | 170 | KRES::Manager<Resource> *manager = ab->resourceManager(); |
183 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 171 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
184 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 172 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
185 | Ticket *ticket = ab->requestSaveTicket( *it ); | 173 | Ticket *ticket = ab->requestSaveTicket( *it ); |
186 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 174 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
187 | if ( !ticket ) { | 175 | if ( !ticket ) { |
188 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) | 176 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) |
189 | .arg( (*it)->resourceName() ) ); | 177 | .arg( (*it)->resourceName() ) ); |
190 | return false; | 178 | return false; |
191 | } | 179 | } |
192 | 180 | ||
193 | if ( !ab->save( ticket ) ) | 181 | if ( !ab->save( ticket ) ) |
194 | ok = false; | 182 | ok = false; |
195 | } | 183 | } |
196 | } | 184 | } |
197 | 185 | ||
198 | return ok; | 186 | return ok; |
199 | } | 187 | } |
200 | 188 | ||
201 | void StdAddressBook::close() | 189 | void StdAddressBook::close() |
202 | { | 190 | { |
203 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? | 191 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? |
204 | //US addressBookDeleter.destructObject(); | 192 | //US addressBookDeleter.destructObject(); |
205 | addressBookDeleter.setObject(0); | 193 | addressBookDeleter.setObject(0); |
206 | 194 | ||
207 | } | 195 | } |
208 | 196 | ||