-rw-r--r-- | kabc/stdaddressbook.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index ec47a4e..181a09e 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -40,185 +40,190 @@ using namespace KABC; | |||
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 | // 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?? |
67 | #ifdef KAB_EMBEDDED | 67 | #ifdef KAB_EMBEDDED |
68 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); | 68 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); |
69 | #else //KAB_EMBEDDED | 69 | #else //KAB_EMBEDDED |
70 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); | 70 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); |
71 | #endif //KAB_EMBEDDED | 71 | #endif //KAB_EMBEDDED |
72 | KStandardDirs::setAppDir( appdir ); | 72 | KStandardDirs::setAppDir( appdir ); |
73 | } | 73 | } |
74 | 74 | ||
75 | return mSelf; | 75 | return mSelf; |
76 | } | 76 | } |
77 | 77 | ||
78 | QString StdAddressBook::setTempAppDir() | 78 | QString StdAddressBook::setTempAppDir() |
79 | { | 79 | { |
80 | QString appDIR = KStandardDirs::appDir(); | 80 | QString appDIR = KStandardDirs::appDir(); |
81 | #ifdef DESKTOP_VERSION | 81 | #ifdef DESKTOP_VERSION |
82 | QString appdir = QDir::homeDirPath(); | 82 | QString appdir = QDir::homeDirPath(); |
83 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) | 83 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) |
84 | appdir += "kaddressbook/"; | 84 | appdir += "kaddressbook/"; |
85 | else | 85 | else |
86 | appdir += "/kaddressbook/"; | 86 | appdir += "/kaddressbook/"; |
87 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); | 87 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); |
88 | #else | 88 | #else |
89 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; | 89 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; |
90 | 90 | ||
91 | KStandardDirs::setAppDir( appdir ); | 91 | KStandardDirs::setAppDir( appdir ); |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | return appDIR; | 94 | return appDIR; |
95 | } | 95 | } |
96 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) | 96 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) |
97 | { | 97 | { |
98 | 98 | ||
99 | if ( !mSelf ) | 99 | if ( !mSelf ) |
100 | { | 100 | { |
101 | QString appdir =StdAddressBook::setTempAppDir(); | 101 | QString appdir =StdAddressBook::setTempAppDir(); |
102 | #ifdef KAB_EMBEDDED | 102 | #ifdef KAB_EMBEDDED |
103 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); | 103 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); |
104 | #else //KAB_EMBEDDED | 104 | #else //KAB_EMBEDDED |
105 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); | 105 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); |
106 | #endif //KAB_EMBEDDED | 106 | #endif //KAB_EMBEDDED |
107 | KStandardDirs::setAppDir( appdir ); | 107 | KStandardDirs::setAppDir( appdir ); |
108 | } | 108 | } |
109 | return mSelf; | 109 | return mSelf; |
110 | } | 110 | } |
111 | 111 | ||
112 | StdAddressBook::StdAddressBook() | 112 | StdAddressBook::StdAddressBook() |
113 | : AddressBook( "kabcrc" ) | 113 | : AddressBook( "kabcrc" ) |
114 | { | 114 | { |
115 | 115 | ||
116 | init( false ); | 116 | init( false ); |
117 | } | 117 | } |
118 | 118 | ||
119 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 119 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
120 | : AddressBook( "kabcrc" ) | 120 | : AddressBook( "kabcrc" ) |
121 | { | 121 | { |
122 | 122 | ||
123 | init( onlyFastResources ); | 123 | init( onlyFastResources ); |
124 | } | 124 | } |
125 | 125 | ||
126 | StdAddressBook::~StdAddressBook() | 126 | StdAddressBook::~StdAddressBook() |
127 | { | 127 | { |
128 | if ( mAutomaticSave ) | 128 | if ( mAutomaticSave ) |
129 | save(); | 129 | save(); |
130 | } | 130 | } |
131 | 131 | ||
132 | void StdAddressBook::init( bool ) | 132 | void StdAddressBook::init( bool ) |
133 | { | 133 | { |
134 | KRES::Manager<Resource> *manager = resourceManager(); | 134 | KRES::Manager<Resource> *manager = resourceManager(); |
135 | KRES::Manager<Resource>::ActiveIterator it; | 135 | KRES::Manager<Resource>::ActiveIterator it; |
136 | 136 | ||
137 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 137 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
138 | (*it)->setAddressBook( this ); | 138 | (*it)->setAddressBook( this ); |
139 | if ( !(*it)->open() ) | 139 | if ( !(*it)->open() ) |
140 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 140 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
141 | } | 141 | } |
142 | 142 | ||
143 | Resource *res = standardResource(); | 143 | Resource *res = standardResource(); |
144 | if ( !res ) { | 144 | if ( !res ) { |
145 | res = manager->createResource( "file" ); | 145 | res = manager->createResource( "file" ); |
146 | if ( res ) | 146 | if ( res ) |
147 | { | 147 | { |
148 | addResource( res ); | 148 | addResource( res ); |
149 | } | 149 | } |
150 | else | 150 | else |
151 | qDebug(" No resource available!!!"); | 151 | qDebug(" No resource available!!!"); |
152 | } | 152 | } |
153 | 153 | ||
154 | setStandardResource( res ); | 154 | setStandardResource( res ); |
155 | manager->writeConfig(); | 155 | manager->writeConfig(); |
156 | 156 | ||
157 | load(); | 157 | load(); |
158 | } | 158 | } |
159 | 159 | ||
160 | bool StdAddressBook::save() | 160 | bool StdAddressBook::save() |
161 | { | 161 | { |
162 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 162 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
163 | 163 | ||
164 | bool ok = true; | 164 | bool ok = true; |
165 | AddressBook *ab = self(); | 165 | AddressBook *ab = self(); |
166 | 166 | ||
167 | ab->deleteRemovedAddressees(); | 167 | ab->deleteRemovedAddressees(); |
168 | 168 | Iterator ait; | |
169 | for ( ait = ab->begin(); ait != ab->end(); ++ait ) { | ||
170 | if ( !(*ait).IDStr().isEmpty() ) { | ||
171 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | ||
172 | } | ||
173 | } | ||
169 | KRES::Manager<Resource>::ActiveIterator it; | 174 | KRES::Manager<Resource>::ActiveIterator it; |
170 | KRES::Manager<Resource> *manager = ab->resourceManager(); | 175 | KRES::Manager<Resource> *manager = ab->resourceManager(); |
171 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 176 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
172 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 177 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
173 | Ticket *ticket = ab->requestSaveTicket( *it ); | 178 | Ticket *ticket = ab->requestSaveTicket( *it ); |
174 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 179 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
175 | if ( !ticket ) { | 180 | if ( !ticket ) { |
176 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) | 181 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) |
177 | .arg( (*it)->resourceName() ) ); | 182 | .arg( (*it)->resourceName() ) ); |
178 | return false; | 183 | return false; |
179 | } | 184 | } |
180 | 185 | ||
181 | if ( !ab->save( ticket ) ) | 186 | if ( !ab->save( ticket ) ) |
182 | ok = false; | 187 | ok = false; |
183 | } | 188 | } |
184 | } | 189 | } |
185 | 190 | ||
186 | return ok; | 191 | return ok; |
187 | } | 192 | } |
188 | 193 | ||
189 | void StdAddressBook::close() | 194 | void StdAddressBook::close() |
190 | { | 195 | { |
191 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? | 196 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? |
192 | //US addressBookDeleter.destructObject(); | 197 | //US addressBookDeleter.destructObject(); |
193 | addressBookDeleter.setObject(0); | 198 | addressBookDeleter.setObject(0); |
194 | 199 | ||
195 | } | 200 | } |
196 | 201 | ||
197 | void StdAddressBook::setAutomaticSave( bool enable ) | 202 | void StdAddressBook::setAutomaticSave( bool enable ) |
198 | { | 203 | { |
199 | mAutomaticSave = enable; | 204 | mAutomaticSave = enable; |
200 | } | 205 | } |
201 | 206 | ||
202 | bool StdAddressBook::automaticSave() | 207 | bool StdAddressBook::automaticSave() |
203 | { | 208 | { |
204 | return mAutomaticSave; | 209 | return mAutomaticSave; |
205 | } | 210 | } |
206 | 211 | ||
207 | // should get const for 4.X | 212 | // should get const for 4.X |
208 | Addressee StdAddressBook::whoAmI() | 213 | Addressee StdAddressBook::whoAmI() |
209 | { | 214 | { |
210 | //US KConfig config( "kabcrc" ); | 215 | //US KConfig config( "kabcrc" ); |
211 | KConfig config( locateLocal("config", "kabcrc") ); | 216 | KConfig config( locateLocal("config", "kabcrc") ); |
212 | config.setGroup( "General" ); | 217 | config.setGroup( "General" ); |
213 | 218 | ||
214 | return findByUid( config.readEntry( "WhoAmI" ) ); | 219 | return findByUid( config.readEntry( "WhoAmI" ) ); |
215 | } | 220 | } |
216 | 221 | ||
217 | void StdAddressBook::setWhoAmI( const Addressee &addr ) | 222 | void StdAddressBook::setWhoAmI( const Addressee &addr ) |
218 | { | 223 | { |
219 | //US KConfig config( "kabcrc" ); | 224 | //US KConfig config( "kabcrc" ); |
220 | KConfig config( locateLocal("config", "kabcrc") ); | 225 | KConfig config( locateLocal("config", "kabcrc") ); |
221 | config.setGroup( "General" ); | 226 | config.setGroup( "General" ); |
222 | 227 | ||
223 | config.writeEntry( "WhoAmI", addr.uid() ); | 228 | config.writeEntry( "WhoAmI", addr.uid() ); |
224 | } | 229 | } |