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