summaryrefslogtreecommitdiffabout
path: root/kabc/stdaddressbook.cpp
Unidiff
Diffstat (limited to 'kabc/stdaddressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/stdaddressbook.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index f17f366..a14ae20 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -1,229 +1,230 @@
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#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
38using namespace KABC; 38using namespace KABC;
39 39
40StdAddressBook *StdAddressBook::mSelf = 0; 40StdAddressBook *StdAddressBook::mSelf = 0;
41bool StdAddressBook::mAutomaticSave = false; 41bool StdAddressBook::mAutomaticSave = false;
42 42
43static KStaticDeleter<StdAddressBook> addressBookDeleter; 43static KStaticDeleter<StdAddressBook> addressBookDeleter;
44 44
45QString StdAddressBook::fileName() 45QString StdAddressBook::fileName()
46{ 46{
47 return locateLocal( "data", "kabc/std.vcf" ); 47 return locateLocal( "data", "kabc/std.vcf" );
48} 48}
49 49
50QString StdAddressBook::directoryName() 50QString StdAddressBook::directoryName()
51{ 51{
52 return locateLocal( "data", "kabc/stdvcf" ); 52 return locateLocal( "data", "kabc/stdvcf" );
53} 53}
54 54
55void StdAddressBook::handleCrash() 55void StdAddressBook::handleCrash()
56{ 56{
57 StdAddressBook::self()->cleanUp(); 57 StdAddressBook::self()->cleanUp();
58} 58}
59 59
60StdAddressBook *StdAddressBook::self() 60StdAddressBook *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
78QString StdAddressBook::setTempAppDir() 78QString 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}
96StdAddressBook *StdAddressBook::self( bool onlyFastResources ) 96StdAddressBook *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
112StdAddressBook::StdAddressBook() 112StdAddressBook::StdAddressBook()
113 : AddressBook( "kabcrc" ) 113 : AddressBook( "kabcrc" )
114{ 114{
115 115
116 init( false ); 116 //init( false );
117} 117}
118 118
119StdAddressBook::StdAddressBook( bool onlyFastResources ) 119StdAddressBook::StdAddressBook( bool onlyFastResources )
120 : AddressBook( "kabcrc" ) 120 : AddressBook( "kabcrc" )
121{ 121{
122 122
123 init( onlyFastResources ); 123 if ( onlyFastResources )
124 init( onlyFastResources );
124} 125}
125 126
126StdAddressBook::~StdAddressBook() 127StdAddressBook::~StdAddressBook()
127{ 128{
128 if ( mAutomaticSave ) 129 if ( mAutomaticSave )
129 save(); 130 save();
130} 131}
131 132
132void StdAddressBook::init( bool ) 133void StdAddressBook::init( bool )
133{ 134{
134 KRES::Manager<Resource> *manager = resourceManager(); 135 KRES::Manager<Resource> *manager = resourceManager();
135 KRES::Manager<Resource>::ActiveIterator it; 136 KRES::Manager<Resource>::ActiveIterator it;
136 137
137 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 138 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
138 (*it)->setAddressBook( this ); 139 (*it)->setAddressBook( this );
139 if ( !(*it)->open() ) 140 if ( !(*it)->open() )
140 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 141 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
141 } 142 }
142 143
143 Resource *res = standardResource(); 144 Resource *res = standardResource();
144 if ( !res ) { 145 if ( !res ) {
145 res = manager->createResource( "file" ); 146 res = manager->createResource( "file" );
146 if ( res ) 147 if ( res )
147 { 148 {
148 addResource( res ); 149 addResource( res );
149 } 150 }
150 else 151 else
151 qDebug(" No resource available!!!"); 152 qDebug(" No resource available!!!");
152 } 153 }
153 154
154 setStandardResource( res ); 155 setStandardResource( res );
155 manager->writeConfig(); 156 manager->writeConfig();
156 157
157 load(); 158 load();
158} 159}
159 160
160bool StdAddressBook::save() 161bool StdAddressBook::save()
161{ 162{
162 kdDebug(5700) << "StdAddressBook::save()" << endl; 163 kdDebug(5700) << "StdAddressBook::save()" << endl;
163 164
164 bool ok = true; 165 bool ok = true;
165 AddressBook *ab = self(); 166 AddressBook *ab = self();
166 167
167 ab->deleteRemovedAddressees(); 168 ab->deleteRemovedAddressees();
168 Iterator ait; 169 Iterator ait;
169 for ( ait = ab->begin(); ait != ab->end(); ++ait ) { 170 for ( ait = ab->begin(); ait != ab->end(); ++ait ) {
170 if ( !(*ait).IDStr().isEmpty() ) { 171 if ( !(*ait).IDStr().isEmpty() ) {
171 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 172 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
172 } 173 }
173 } 174 }
174 KRES::Manager<Resource>::ActiveIterator it; 175 KRES::Manager<Resource>::ActiveIterator it;
175 KRES::Manager<Resource> *manager = ab->resourceManager(); 176 KRES::Manager<Resource> *manager = ab->resourceManager();
176 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 177 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
177 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 178 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
178 Ticket *ticket = ab->requestSaveTicket( *it ); 179 Ticket *ticket = ab->requestSaveTicket( *it );
179// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 180// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
180 if ( !ticket ) { 181 if ( !ticket ) {
181 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 182 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
182 .arg( (*it)->resourceName() ) ); 183 .arg( (*it)->resourceName() ) );
183 return false; 184 return false;
184 } 185 }
185 186
186 if ( !ab->save( ticket ) ) 187 if ( !ab->save( ticket ) )
187 ok = false; 188 ok = false;
188 } 189 }
189 } 190 }
190 191
191 return ok; 192 return ok;
192} 193}
193 194
194void StdAddressBook::close() 195void StdAddressBook::close()
195{ 196{
196//US destructObject is not defined on my system???. Is setObject(0) the same ??? 197//US destructObject is not defined on my system???. Is setObject(0) the same ???
197//US addressBookDeleter.destructObject(); 198//US addressBookDeleter.destructObject();
198 addressBookDeleter.setObject(0); 199 addressBookDeleter.setObject(0);
199 200
200} 201}
201 202
202void StdAddressBook::setAutomaticSave( bool enable ) 203void StdAddressBook::setAutomaticSave( bool enable )
203{ 204{
204 mAutomaticSave = enable; 205 mAutomaticSave = enable;
205} 206}
206 207
207bool StdAddressBook::automaticSave() 208bool StdAddressBook::automaticSave()
208{ 209{
209 return mAutomaticSave; 210 return mAutomaticSave;
210} 211}
211 212
212// should get const for 4.X 213// should get const for 4.X
213Addressee StdAddressBook::whoAmI() 214Addressee StdAddressBook::whoAmI()
214{ 215{
215//US KConfig config( "kabcrc" ); 216//US KConfig config( "kabcrc" );
216 KConfig config( locateLocal("config", "kabcrc") ); 217 KConfig config( locateLocal("config", "kabcrc") );
217 config.setGroup( "General" ); 218 config.setGroup( "General" );
218 219
219 return findByUid( config.readEntry( "WhoAmI" ) ); 220 return findByUid( config.readEntry( "WhoAmI" ) );
220} 221}
221 222
222void StdAddressBook::setWhoAmI( const Addressee &addr ) 223void StdAddressBook::setWhoAmI( const Addressee &addr )
223{ 224{
224//US KConfig config( "kabcrc" ); 225//US KConfig config( "kabcrc" );
225 KConfig config( locateLocal("config", "kabcrc") ); 226 KConfig config( locateLocal("config", "kabcrc") );
226 config.setGroup( "General" ); 227 config.setGroup( "General" );
227 228
228 config.writeEntry( "WhoAmI", addr.uid() ); 229 config.writeEntry( "WhoAmI", addr.uid() );
229} 230}