summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/stdaddressbook.cpp27
-rw-r--r--kabc/stdaddressbook.h2
2 files changed, 26 insertions, 3 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index a14ae20..43d9fde 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -1,230 +1,251 @@
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}
59StdAddressBook *StdAddressBook::selfNoLoad()
60{
61
62 if ( !mSelf )
63 {
64 QString appdir = StdAddressBook::setTempAppDir();
65// US im am not sure why I have to use the other format here??
66#ifdef KAB_EMBEDDED
67 mSelf = addressBookDeleter.setObject( new StdAddressBook ( QString() ) );
68#else //KAB_EMBEDDED
69 addressBookDeleter.setObject( mSelf, new StdAddressBook( QString() ) );
70#endif //KAB_EMBEDDED
71 KStandardDirs::setAppDir( appdir );
72 }
73
74 return mSelf;
75}
59 76
60StdAddressBook *StdAddressBook::self() 77StdAddressBook *StdAddressBook::self()
61{ 78{
62 79
63 if ( !mSelf ) 80 if ( !mSelf )
64 { 81 {
65 QString appdir = StdAddressBook::setTempAppDir(); 82 QString appdir = StdAddressBook::setTempAppDir();
66// US im am not sure why I have to use the other format here?? 83// US im am not sure why I have to use the other format here??
67#ifdef KAB_EMBEDDED 84#ifdef KAB_EMBEDDED
68 mSelf = addressBookDeleter.setObject( new StdAddressBook ); 85 mSelf = addressBookDeleter.setObject( new StdAddressBook );
69#else //KAB_EMBEDDED 86#else //KAB_EMBEDDED
70 addressBookDeleter.setObject( mSelf, new StdAddressBook ); 87 addressBookDeleter.setObject( mSelf, new StdAddressBook );
71#endif //KAB_EMBEDDED 88#endif //KAB_EMBEDDED
72 KStandardDirs::setAppDir( appdir ); 89 KStandardDirs::setAppDir( appdir );
73 } 90 }
74 91
75 return mSelf; 92 return mSelf;
76} 93}
77 94
78QString StdAddressBook::setTempAppDir() 95QString StdAddressBook::setTempAppDir()
79{ 96{
80 QString appDIR = KStandardDirs::appDir(); 97 QString appDIR = KStandardDirs::appDir();
81#ifdef DESKTOP_VERSION 98#ifdef DESKTOP_VERSION
82 QString appdir = QDir::homeDirPath(); 99 QString appdir = QDir::homeDirPath();
83 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) 100 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
84 appdir += "kaddressbook/"; 101 appdir += "kaddressbook/";
85 else 102 else
86 appdir += "/kaddressbook/"; 103 appdir += "/kaddressbook/";
87 KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); 104 KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
88#else 105#else
89 QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; 106 QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook";
90 107
91 KStandardDirs::setAppDir( appdir ); 108 KStandardDirs::setAppDir( appdir );
92#endif 109#endif
93 110
94 return appDIR; 111 return appDIR;
95} 112}
96StdAddressBook *StdAddressBook::self( bool onlyFastResources ) 113StdAddressBook *StdAddressBook::self( bool onlyFastResources )
97{ 114{
98 115
99 if ( !mSelf ) 116 if ( !mSelf )
100 { 117 {
101 QString appdir =StdAddressBook::setTempAppDir(); 118 QString appdir =StdAddressBook::setTempAppDir();
102#ifdef KAB_EMBEDDED 119#ifdef KAB_EMBEDDED
103 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); 120 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) );
104#else //KAB_EMBEDDED 121#else //KAB_EMBEDDED
105 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); 122 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) );
106#endif //KAB_EMBEDDED 123#endif //KAB_EMBEDDED
107 KStandardDirs::setAppDir( appdir ); 124 KStandardDirs::setAppDir( appdir );
108 } 125 }
109 return mSelf; 126 return mSelf;
110} 127}
128StdAddressBook::StdAddressBook( QString )
129 : AddressBook( "kabcrc" )
130{
131
132}
111 133
112StdAddressBook::StdAddressBook() 134StdAddressBook::StdAddressBook()
113 : AddressBook( "kabcrc" ) 135 : AddressBook( "kabcrc" )
114{ 136{
115 137
116 //init( false ); 138 init( false );
117} 139}
118 140
119StdAddressBook::StdAddressBook( bool onlyFastResources ) 141StdAddressBook::StdAddressBook( bool onlyFastResources )
120 : AddressBook( "kabcrc" ) 142 : AddressBook( "kabcrc" )
121{ 143{
122 144
123 if ( onlyFastResources ) 145 init( onlyFastResources );
124 init( onlyFastResources );
125} 146}
126 147
127StdAddressBook::~StdAddressBook() 148StdAddressBook::~StdAddressBook()
128{ 149{
129 if ( mAutomaticSave ) 150 if ( mAutomaticSave )
130 save(); 151 save();
131} 152}
132 153
133void StdAddressBook::init( bool ) 154void StdAddressBook::init( bool )
134{ 155{
135 KRES::Manager<Resource> *manager = resourceManager(); 156 KRES::Manager<Resource> *manager = resourceManager();
136 KRES::Manager<Resource>::ActiveIterator it; 157 KRES::Manager<Resource>::ActiveIterator it;
137 158
138 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 159 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
139 (*it)->setAddressBook( this ); 160 (*it)->setAddressBook( this );
140 if ( !(*it)->open() ) 161 if ( !(*it)->open() )
141 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 162 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
142 } 163 }
143 164
144 Resource *res = standardResource(); 165 Resource *res = standardResource();
145 if ( !res ) { 166 if ( !res ) {
146 res = manager->createResource( "file" ); 167 res = manager->createResource( "file" );
147 if ( res ) 168 if ( res )
148 { 169 {
149 addResource( res ); 170 addResource( res );
150 } 171 }
151 else 172 else
152 qDebug(" No resource available!!!"); 173 qDebug(" No resource available!!!");
153 } 174 }
154 175
155 setStandardResource( res ); 176 setStandardResource( res );
156 manager->writeConfig(); 177 manager->writeConfig();
157 178
158 load(); 179 load();
159} 180}
160 181
161bool StdAddressBook::save() 182bool StdAddressBook::save()
162{ 183{
163 kdDebug(5700) << "StdAddressBook::save()" << endl; 184 kdDebug(5700) << "StdAddressBook::save()" << endl;
164 185
165 bool ok = true; 186 bool ok = true;
166 AddressBook *ab = self(); 187 AddressBook *ab = self();
167 188
168 ab->deleteRemovedAddressees(); 189 ab->deleteRemovedAddressees();
169 Iterator ait; 190 Iterator ait;
170 for ( ait = ab->begin(); ait != ab->end(); ++ait ) { 191 for ( ait = ab->begin(); ait != ab->end(); ++ait ) {
171 if ( !(*ait).IDStr().isEmpty() ) { 192 if ( !(*ait).IDStr().isEmpty() ) {
172 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 193 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
173 } 194 }
174 } 195 }
175 KRES::Manager<Resource>::ActiveIterator it; 196 KRES::Manager<Resource>::ActiveIterator it;
176 KRES::Manager<Resource> *manager = ab->resourceManager(); 197 KRES::Manager<Resource> *manager = ab->resourceManager();
177 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 198 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
178 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 199 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
179 Ticket *ticket = ab->requestSaveTicket( *it ); 200 Ticket *ticket = ab->requestSaveTicket( *it );
180// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 201// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
181 if ( !ticket ) { 202 if ( !ticket ) {
182 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 203 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
183 .arg( (*it)->resourceName() ) ); 204 .arg( (*it)->resourceName() ) );
184 return false; 205 return false;
185 } 206 }
186 207
187 if ( !ab->save( ticket ) ) 208 if ( !ab->save( ticket ) )
188 ok = false; 209 ok = false;
189 } 210 }
190 } 211 }
191 212
192 return ok; 213 return ok;
193} 214}
194 215
195void StdAddressBook::close() 216void StdAddressBook::close()
196{ 217{
197//US destructObject is not defined on my system???. Is setObject(0) the same ??? 218//US destructObject is not defined on my system???. Is setObject(0) the same ???
198//US addressBookDeleter.destructObject(); 219//US addressBookDeleter.destructObject();
199 addressBookDeleter.setObject(0); 220 addressBookDeleter.setObject(0);
200 221
201} 222}
202 223
203void StdAddressBook::setAutomaticSave( bool enable ) 224void StdAddressBook::setAutomaticSave( bool enable )
204{ 225{
205 mAutomaticSave = enable; 226 mAutomaticSave = enable;
206} 227}
207 228
208bool StdAddressBook::automaticSave() 229bool StdAddressBook::automaticSave()
209{ 230{
210 return mAutomaticSave; 231 return mAutomaticSave;
211} 232}
212 233
213// should get const for 4.X 234// should get const for 4.X
214Addressee StdAddressBook::whoAmI() 235Addressee StdAddressBook::whoAmI()
215{ 236{
216//US KConfig config( "kabcrc" ); 237//US KConfig config( "kabcrc" );
217 KConfig config( locateLocal("config", "kabcrc") ); 238 KConfig config( locateLocal("config", "kabcrc") );
218 config.setGroup( "General" ); 239 config.setGroup( "General" );
219 240
220 return findByUid( config.readEntry( "WhoAmI" ) ); 241 return findByUid( config.readEntry( "WhoAmI" ) );
221} 242}
222 243
223void StdAddressBook::setWhoAmI( const Addressee &addr ) 244void StdAddressBook::setWhoAmI( const Addressee &addr )
224{ 245{
225//US KConfig config( "kabcrc" ); 246//US KConfig config( "kabcrc" );
226 KConfig config( locateLocal("config", "kabcrc") ); 247 KConfig config( locateLocal("config", "kabcrc") );
227 config.setGroup( "General" ); 248 config.setGroup( "General" );
228 249
229 config.writeEntry( "WhoAmI", addr.uid() ); 250 config.writeEntry( "WhoAmI", addr.uid() );
230} 251}
diff --git a/kabc/stdaddressbook.h b/kabc/stdaddressbook.h
index cf130b3..3cd6363 100644
--- a/kabc/stdaddressbook.h
+++ b/kabc/stdaddressbook.h
@@ -1,151 +1,153 @@
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#ifndef KABC_STDADDRESSBOOK_H 28#ifndef KABC_STDADDRESSBOOK_H
29#define KABC_STDADDRESSBOOK_H 29#define KABC_STDADDRESSBOOK_H
30 30
31#include "addressbook.h" 31#include "addressbook.h"
32 32
33namespace KABC { 33namespace KABC {
34 34
35/** 35/**
36 Standard KDE address book 36 Standard KDE address book
37 37
38 This class provides access to the standard KDE address book shared by all 38 This class provides access to the standard KDE address book shared by all
39 applications. 39 applications.
40 40
41 It's implemented as a singleton. Use @ref self() to get the address book 41 It's implemented as a singleton. Use @ref self() to get the address book
42 object. On the first self() call the address book also gets loaded. 42 object. On the first self() call the address book also gets loaded.
43 43
44 Example: 44 Example:
45 45
46 <pre> 46 <pre>
47 KABC::AddressBook *ab = KABC::StdAddressBook::self(); 47 KABC::AddressBook *ab = KABC::StdAddressBook::self();
48 48
49 KABC::AddressBook::Iterator it; 49 KABC::AddressBook::Iterator it;
50 for ( it = ab->begin(); it != ab->end(); ++it ) { 50 for ( it = ab->begin(); it != ab->end(); ++it ) {
51 kdDebug() << "UID=" << (*it).uid() << endl; 51 kdDebug() << "UID=" << (*it).uid() << endl;
52 52
53 // do some other stuff 53 // do some other stuff
54 } 54 }
55 55
56 KABC::StdAddressBook::save(); 56 KABC::StdAddressBook::save();
57 </pre> 57 </pre>
58*/ 58*/
59class StdAddressBook : public AddressBook 59class StdAddressBook : public AddressBook
60{ 60{
61 public: 61 public:
62 62
63 /** 63 /**
64 Destructor. 64 Destructor.
65 */ 65 */
66 ~StdAddressBook(); 66 ~StdAddressBook();
67 67
68 /** 68 /**
69 Return the standard addressbook object. It also loads slow resources. 69 Return the standard addressbook object. It also loads slow resources.
70 It is the same as self(false); . 70 It is the same as self(false); .
71 */ 71 */
72 static StdAddressBook *self(); 72 static StdAddressBook *self();
73 static StdAddressBook *selfNoLoad();
73 74
74 /** 75 /**
75 This is the same as above, but with specified 76 This is the same as above, but with specified
76 behaviour of resource loading. 77 behaviour of resource loading.
77 78
78 @param onlyFastResource Only resources marked as 'fast' should be loaded 79 @param onlyFastResource Only resources marked as 'fast' should be loaded
79 */ 80 */
80 // FIXME for KDE4 return StdAddressBook and merge with the metod above -zecke 81 // FIXME for KDE4 return StdAddressBook and merge with the metod above -zecke
81 static StdAddressBook *self( bool onlyFastResources ); 82 static StdAddressBook *self( bool onlyFastResources );
82 83
83 /** 84 /**
84 Save the standard address book to disk. 85 Save the standard address book to disk.
85 */ 86 */
86 static bool save(); 87 static bool save();
87 88
88 /** 89 /**
89 Call this method in your crash handler to allow the library clean up 90 Call this method in your crash handler to allow the library clean up
90 possible locks. 91 possible locks.
91 */ 92 */
92 static void handleCrash(); 93 static void handleCrash();
93 94
94 /** 95 /**
95 Returns the default file name for vcard-based addressbook 96 Returns the default file name for vcard-based addressbook
96 */ 97 */
97 static QString fileName(); 98 static QString fileName();
98 99
99 /** 100 /**
100 Returns the default directory name for vcard-based addressbook 101 Returns the default directory name for vcard-based addressbook
101 */ 102 */
102 static QString directoryName(); 103 static QString directoryName();
103 104
104 /** 105 /**
105 Set the automatic save property of the address book. 106 Set the automatic save property of the address book.
106 If @p enable is TRUE (default) the address book is saved at 107 If @p enable is TRUE (default) the address book is saved at
107 destruction time otherwise you have to call @ref save() to 108 destruction time otherwise you have to call @ref save() to
108 explicitely save it. 109 explicitely save it.
109 */ 110 */
110 static void setAutomaticSave( bool enable ); 111 static void setAutomaticSave( bool enable );
111 112
112 /** 113 /**
113 Closes the address book. Depending on @ref automaticSave() it will 114 Closes the address book. Depending on @ref automaticSave() it will
114 save the address book first. 115 save the address book first.
115 */ 116 */
116 static void close(); 117 static void close();
117 118
118 /** 119 /**
119 Returns whether the address book is saved at destruction time. 120 Returns whether the address book is saved at destruction time.
120 See also @ref setAutomaticSave(). 121 See also @ref setAutomaticSave().
121 */ 122 */
122 static bool automaticSave(); 123 static bool automaticSave();
123 124
124 /** 125 /**
125 Returns the contact, that is associated with the owner of the 126 Returns the contact, that is associated with the owner of the
126 address book. This contact should be used by other programs 127 address book. This contact should be used by other programs
127 to access user specific data. 128 to access user specific data.
128 */ 129 */
129 Addressee whoAmI(); 130 Addressee whoAmI();
130 131
131 /** 132 /**
132 Sets the users contact. See @ref whoAmI() for more information. 133 Sets the users contact. See @ref whoAmI() for more information.
133 134
134 @param uid The uid of the users contact. 135 @param uid The uid of the users contact.
135 */ 136 */
136 void setWhoAmI( const Addressee &addr ); 137 void setWhoAmI( const Addressee &addr );
137 void init( bool onlyFastResources ); 138 void init( bool onlyFastResources );
138 139
139 protected: 140 protected:
140 StdAddressBook(); 141 StdAddressBook();
142 StdAddressBook( QString );
141 StdAddressBook( bool onlyFastResources ); 143 StdAddressBook( bool onlyFastResources );
142 144
143 145
144 private: 146 private:
145 static QString setTempAppDir(); 147 static QString setTempAppDir();
146 static StdAddressBook *mSelf; 148 static StdAddressBook *mSelf;
147 static bool mAutomaticSave; 149 static bool mAutomaticSave;
148}; 150};
149 151
150} 152}
151#endif 153#endif