• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
stdaddressbook.cpp
1 /*
2  This file is part of libtdeabc.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
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
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <stdlib.h>
22 
23 #include <tdeapplication.h>
24 #include <kcrash.h>
25 #include <kdebug.h>
26 #include <tdelocale.h>
27 #include <tderesources/manager.h>
28 #include <ksimpleconfig.h>
29 #include <kstandarddirs.h>
30 #include <kstaticdeleter.h>
31 
32 #include "resource.h"
33 
34 #include "stdaddressbook.h"
35 
36 using namespace TDEABC;
37 
38 StdAddressBook *StdAddressBook::mSelf = 0;
39 bool StdAddressBook::mAutomaticSave = true;
40 
41 static KStaticDeleter<StdAddressBook> addressBookDeleter;
42 
43 TQString StdAddressBook::fileName()
44 {
45  return locateLocal( "data", "tdeabc/std.vcf" );
46 }
47 
48 TQString StdAddressBook::directoryName()
49 {
50  return locateLocal( "data", "tdeabc/stdvcf" );
51 }
52 
53 void StdAddressBook::handleCrash()
54 {
55 }
56 
57 StdAddressBook *StdAddressBook::self()
58 {
59  if ( !mSelf )
60  addressBookDeleter.setObject( mSelf, new StdAddressBook );
61 
62  return mSelf;
63 }
64 
65 StdAddressBook *StdAddressBook::self( bool asynchronous )
66 {
67  if ( !mSelf )
68  addressBookDeleter.setObject( mSelf, new StdAddressBook( asynchronous ) );
69 
70  return mSelf;
71 }
72 
73 StdAddressBook::StdAddressBook()
74  : AddressBook( "" )
75 {
76  kdDebug(5700) << "StdAddressBook::StdAddressBook()" << endl;
77 
78  init( false );
79 }
80 
81 StdAddressBook::StdAddressBook( bool asynchronous )
82  : AddressBook( "" )
83 {
84  kdDebug(5700) << "StdAddressBook::StdAddressBook( bool )" << endl;
85 
86  init( asynchronous );
87 }
88 
89 StdAddressBook::~StdAddressBook()
90 {
91  if ( mAutomaticSave )
92  saveAll();
93 }
94 
95 void StdAddressBook::init( bool asynchronous )
96 {
97  KRES::Manager<Resource> *manager = resourceManager();
98 
99  KRES::Manager<Resource>::ActiveIterator it;
100  for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
101  (*it)->setAddressBook( this );
102  if ( !(*it)->open() ) {
103  error( TQString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
104  continue;
105  }
106  connect( *it, TQT_SIGNAL( loadingFinished( Resource* ) ),
107  this, TQT_SLOT( resourceLoadingFinished( Resource* ) ) );
108  connect( *it, TQT_SIGNAL( savingFinished( Resource* ) ),
109  this, TQT_SLOT( resourceSavingFinished( Resource* ) ) );
110 
111  connect( *it, TQT_SIGNAL( loadingError( Resource*, const TQString& ) ),
112  this, TQT_SLOT( resourceLoadingError( Resource*, const TQString& ) ) );
113  connect( *it, TQT_SIGNAL( savingError( Resource*, const TQString& ) ),
114  this, TQT_SLOT( resourceSavingError( Resource*, const TQString& ) ) );
115  }
116 
117  Resource *res = standardResource();
118  if ( !res ) {
119  res = manager->createResource( "file" );
120  if ( res )
121  addResource( res );
122  else
123  kdDebug(5700) << "No resource available!!!" << endl;
124  }
125 
126  setStandardResource( res );
127  manager->writeConfig();
128 
129  if ( asynchronous )
130  asyncLoad();
131  else
132  load();
133 }
134 
135 bool StdAddressBook::saveAll()
136 {
137  kdDebug(5700) << "StdAddressBook::saveAll()" << endl;
138  bool ok = true;
139 
140  deleteRemovedAddressees();
141 
142  KRES::Manager<Resource>::ActiveIterator it;
143  KRES::Manager<Resource> *manager = resourceManager();
144  for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
145  if ( !(*it)->readOnly() && (*it)->isOpen() ) {
146  Ticket *ticket = requestSaveTicket( *it );
147  if ( !ticket ) {
148  error( i18n( "Unable to save to resource '%1'. It is locked." )
149  .arg( (*it)->resourceName() ) );
150  return false;
151  }
152 
153  if ( !AddressBook::save( ticket ) ) {
154  ok = false;
155  releaseSaveTicket( ticket );
156  }
157  }
158  }
159 
160  return ok;
161 }
162 
163 bool StdAddressBook::save()
164 {
165  kdDebug(5700) << "StdAddressBook::save()" << endl;
166 
167  if ( mSelf )
168  return mSelf->saveAll();
169  else
170  return true;
171 }
172 
173 void StdAddressBook::close()
174 {
175  addressBookDeleter.destructObject();
176 }
177 
178 void StdAddressBook::setAutomaticSave( bool enable )
179 {
180  mAutomaticSave = enable;
181 }
182 
183 bool StdAddressBook::automaticSave()
184 {
185  return mAutomaticSave;
186 }
187 
188 // should get const for 4.X
189 Addressee StdAddressBook::whoAmI()
190 {
191  TDEConfig config( "tdeabcrc" );
192  config.setGroup( "General" );
193 
194  return findByUid( config.readEntry( "WhoAmI" ) );
195 }
196 
197 void StdAddressBook::setWhoAmI( const Addressee &addr )
198 {
199  TDEConfig config( "tdeabcrc" );
200  config.setGroup( "General" );
201 
202  config.writeEntry( "WhoAmI", addr.uid() );
203 }

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.