summaryrefslogtreecommitdiffabout
path: root/kabc/stdaddressbook.cpp
Unidiff
Diffstat (limited to 'kabc/stdaddressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/stdaddressbook.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index 8faaaef..144a9dc 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -1,233 +1,239 @@
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/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31#include <kapplication.h> 31#include <kapplication.h>
32#include <kcrash.h> 32#include <kcrash.h>
33#include <ksimpleconfig.h> 33#include <ksimpleconfig.h>
34*/ 34*/
35 35
36#ifndef DESKTOP_VERSION
37#include <qpe/global.h>
38#else
39#include <qdir.h>
40#endif
41
36#include "resource.h" 42#include "resource.h"
37#include <kresources/manager.h> 43#include <kresources/manager.h>
38#include <kdebug.h> 44#include <kdebug.h>
39#include <klocale.h> 45#include <klocale.h>
40#include <kstaticdeleter.h> 46#include <kstaticdeleter.h>
41#include <kstandarddirs.h> 47#include <kstandarddirs.h>
42 48
43#include "stdaddressbook.h" 49#include "stdaddressbook.h"
44 50
45using namespace KABC; 51using namespace KABC;
46 52
47StdAddressBook *StdAddressBook::mSelf = 0; 53StdAddressBook *StdAddressBook::mSelf = 0;
48bool StdAddressBook::mAutomaticSave = true; 54bool StdAddressBook::mAutomaticSave = true;
49 55
50static KStaticDeleter<StdAddressBook> addressBookDeleter; 56static KStaticDeleter<StdAddressBook> addressBookDeleter;
51 57
52QString StdAddressBook::fileName() 58QString StdAddressBook::fileName()
53{ 59{
54 return locateLocal( "data", "kabc/std.vcf" ); 60 return locateLocal( "data", "kabc/std.vcf" );
55} 61}
56 62
57QString StdAddressBook::directoryName() 63QString StdAddressBook::directoryName()
58{ 64{
59 return locateLocal( "data", "kabc/stdvcf" ); 65 return locateLocal( "data", "kabc/stdvcf" );
60} 66}
61 67
62void StdAddressBook::handleCrash() 68void StdAddressBook::handleCrash()
63{ 69{
64 StdAddressBook::self()->cleanUp(); 70 StdAddressBook::self()->cleanUp();
65} 71}
66 72
67StdAddressBook *StdAddressBook::self() 73StdAddressBook *StdAddressBook::self()
68{ 74{
69 75
70 if ( !mSelf ) 76 if ( !mSelf )
71 { 77 {
72 QString appdir = StdAddressBook::setTempAppDir(); 78 QString appdir = StdAddressBook::setTempAppDir();
73 79
74 kdDebug(5700) << "StdAddressBook::self()" << endl; 80 kdDebug(5700) << "StdAddressBook::self()" << endl;
75// US im am not sure why I have to use the other format here?? 81// US im am not sure why I have to use the other format here??
76#ifdef KAB_EMBEDDED 82#ifdef KAB_EMBEDDED
77 mSelf = addressBookDeleter.setObject( new StdAddressBook ); 83 mSelf = addressBookDeleter.setObject( new StdAddressBook );
78#else //KAB_EMBEDDED 84#else //KAB_EMBEDDED
79 addressBookDeleter.setObject( mSelf, new StdAddressBook ); 85 addressBookDeleter.setObject( mSelf, new StdAddressBook );
80#endif //KAB_EMBEDDED 86#endif //KAB_EMBEDDED
81 KStandardDirs::setAppDir( appdir ); 87 KStandardDirs::setAppDir( appdir );
82 } 88 }
83 89
84 return mSelf; 90 return mSelf;
85} 91}
86 92
87QString StdAddressBook::setTempAppDir() 93QString StdAddressBook::setTempAppDir()
88{ 94{
89 QString appDIR = KStandardDirs::appDir(); 95 QString appDIR = KStandardDirs::appDir();
90#ifdef DESKTOP_VERSION 96#ifdef DESKTOP_VERSION
91 QString appdir = QDir::homeDirPath(); 97 QString appdir = QDir::homeDirPath();
92 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) 98 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
93 appdir += "kaddressbook/"; 99 appdir += "kaddressbook/";
94 else 100 else
95 appdir += "/kaddressbook/"; 101 appdir += "/kaddressbook/";
96 KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); 102 KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
97#else 103#else
98 KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) ); 104 KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) );
99#endif 105#endif
100 106
101 return appDIR; 107 return appDIR;
102} 108}
103StdAddressBook *StdAddressBook::self( bool onlyFastResources ) 109StdAddressBook *StdAddressBook::self( bool onlyFastResources )
104{ 110{
105 111
106 if ( !mSelf ) 112 if ( !mSelf )
107 { 113 {
108 QString appdir =StdAddressBook::setTempAppDir(); 114 QString appdir =StdAddressBook::setTempAppDir();
109#ifdef KAB_EMBEDDED 115#ifdef KAB_EMBEDDED
110 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); 116 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) );
111#else //KAB_EMBEDDED 117#else //KAB_EMBEDDED
112 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); 118 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) );
113#endif //KAB_EMBEDDED 119#endif //KAB_EMBEDDED
114 KStandardDirs::setAppDir( appdir ); 120 KStandardDirs::setAppDir( appdir );
115 } 121 }
116 return mSelf; 122 return mSelf;
117} 123}
118 124
119StdAddressBook::StdAddressBook() 125StdAddressBook::StdAddressBook()
120//US : AddressBook( "kabcrc" ) 126//US : AddressBook( "kabcrc" )
121 : AddressBook( locateLocal( "config", "kabcrc") ) 127 : AddressBook( locateLocal( "config", "kabcrc") )
122{ 128{
123 129
124 init( false ); 130 init( false );
125} 131}
126 132
127StdAddressBook::StdAddressBook( bool onlyFastResources ) 133StdAddressBook::StdAddressBook( bool onlyFastResources )
128//US : AddressBook( "kabcrc" ) 134//US : AddressBook( "kabcrc" )
129 : AddressBook( locateLocal( "config", "kabcrc") ) 135 : AddressBook( locateLocal( "config", "kabcrc") )
130{ 136{
131 137
132 init( onlyFastResources ); 138 init( onlyFastResources );
133} 139}
134 140
135StdAddressBook::~StdAddressBook() 141StdAddressBook::~StdAddressBook()
136{ 142{
137 if ( mAutomaticSave ) 143 if ( mAutomaticSave )
138 save(); 144 save();
139} 145}
140 146
141void StdAddressBook::init( bool ) 147void StdAddressBook::init( bool )
142{ 148{
143 KRES::Manager<Resource> *manager = resourceManager(); 149 KRES::Manager<Resource> *manager = resourceManager();
144 KRES::Manager<Resource>::ActiveIterator it; 150 KRES::Manager<Resource>::ActiveIterator it;
145 151
146 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 152 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
147 (*it)->setAddressBook( this ); 153 (*it)->setAddressBook( this );
148 if ( !(*it)->open() ) 154 if ( !(*it)->open() )
149 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 155 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
150 } 156 }
151 157
152 Resource *res = standardResource(); 158 Resource *res = standardResource();
153 if ( !res ) { 159 if ( !res ) {
154 res = manager->createResource( "file" ); 160 res = manager->createResource( "file" );
155 if ( res ) 161 if ( res )
156 { 162 {
157 addResource( res ); 163 addResource( res );
158 } 164 }
159 else 165 else
160 kdDebug(5700) << "No resource available!!!" << endl; 166 kdDebug(5700) << "No resource available!!!" << endl;
161 } 167 }
162 168
163 setStandardResource( res ); 169 setStandardResource( res );
164 manager->writeConfig(); 170 manager->writeConfig();
165 171
166 load(); 172 load();
167} 173}
168 174
169bool StdAddressBook::save() 175bool StdAddressBook::save()
170{ 176{
171 kdDebug(5700) << "StdAddressBook::save()" << endl; 177 kdDebug(5700) << "StdAddressBook::save()" << endl;
172 178
173 bool ok = true; 179 bool ok = true;
174 AddressBook *ab = self(); 180 AddressBook *ab = self();
175 181
176 ab->deleteRemovedAddressees(); 182 ab->deleteRemovedAddressees();
177 183
178 KRES::Manager<Resource>::ActiveIterator it; 184 KRES::Manager<Resource>::ActiveIterator it;
179 KRES::Manager<Resource> *manager = ab->resourceManager(); 185 KRES::Manager<Resource> *manager = ab->resourceManager();
180 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 186 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
181 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 187 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
182 Ticket *ticket = ab->requestSaveTicket( *it ); 188 Ticket *ticket = ab->requestSaveTicket( *it );
183// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 189// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
184 if ( !ticket ) { 190 if ( !ticket ) {
185 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 191 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
186 .arg( (*it)->resourceName() ) ); 192 .arg( (*it)->resourceName() ) );
187 return false; 193 return false;
188 } 194 }
189 195
190 if ( !ab->save( ticket ) ) 196 if ( !ab->save( ticket ) )
191 ok = false; 197 ok = false;
192 } 198 }
193 } 199 }
194 200
195 return ok; 201 return ok;
196} 202}
197 203
198void StdAddressBook::close() 204void StdAddressBook::close()
199{ 205{
200//US destructObject is not defined on my system???. Is setObject(0) the same ??? 206//US destructObject is not defined on my system???. Is setObject(0) the same ???
201//US addressBookDeleter.destructObject(); 207//US addressBookDeleter.destructObject();
202 addressBookDeleter.setObject(0); 208 addressBookDeleter.setObject(0);
203 209
204} 210}
205 211
206void StdAddressBook::setAutomaticSave( bool enable ) 212void StdAddressBook::setAutomaticSave( bool enable )
207{ 213{
208 mAutomaticSave = enable; 214 mAutomaticSave = enable;
209} 215}
210 216
211bool StdAddressBook::automaticSave() 217bool StdAddressBook::automaticSave()
212{ 218{
213 return mAutomaticSave; 219 return mAutomaticSave;
214} 220}
215 221
216// should get const for 4.X 222// should get const for 4.X
217Addressee StdAddressBook::whoAmI() 223Addressee StdAddressBook::whoAmI()
218{ 224{
219//US KConfig config( "kabcrc" ); 225//US KConfig config( "kabcrc" );
220 KConfig config( locateLocal("config", "kabcrc") ); 226 KConfig config( locateLocal("config", "kabcrc") );
221 config.setGroup( "General" ); 227 config.setGroup( "General" );
222 228
223 return findByUid( config.readEntry( "WhoAmI" ) ); 229 return findByUid( config.readEntry( "WhoAmI" ) );
224} 230}
225 231
226void StdAddressBook::setWhoAmI( const Addressee &addr ) 232void StdAddressBook::setWhoAmI( const Addressee &addr )
227{ 233{
228//US KConfig config( "kabcrc" ); 234//US KConfig config( "kabcrc" );
229 KConfig config( locateLocal("config", "kabcrc") ); 235 KConfig config( locateLocal("config", "kabcrc") );
230 config.setGroup( "General" ); 236 config.setGroup( "General" );
231 237
232 config.writeEntry( "WhoAmI", addr.uid() ); 238 config.writeEntry( "WhoAmI", addr.uid() );
233} 239}