kaddressbook Library API Documentation

undocmds.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (C) 1999 Don Sanders <sanders@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <qtextstream.h> 00025 #include <qapplication.h> 00026 #include <qclipboard.h> 00027 00028 #include <klocale.h> 00029 #include <kdebug.h> 00030 #include <kapplication.h> 00031 #include <kabc/addressbook.h> 00032 00033 #include "addresseeutil.h" 00034 #include "addresseeconfig.h" 00035 #include "core.h" 00036 #include "kablock.h" 00037 00038 #include "undocmds.h" 00039 00041 // PwDelete Methods 00042 00043 PwDeleteCommand::PwDeleteCommand( KABC::AddressBook *ab, 00044 const QStringList &uidList) 00045 : Command( ab ), mAddresseeList(), mUIDList( uidList ) 00046 { 00047 redo(); 00048 } 00049 00050 PwDeleteCommand::~PwDeleteCommand() 00051 { 00052 } 00053 00054 QString PwDeleteCommand::name() 00055 { 00056 return i18n( "Delete" ); 00057 } 00058 00059 bool PwDeleteCommand::undo() 00060 { 00061 // Put it back in the document 00062 KABC::Addressee::List::Iterator it; 00063 00064 // lock resources 00065 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) 00066 lock()->lock( (*it).resource() ); 00067 00068 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) { 00069 addressBook()->insertAddressee( *it ); 00070 lock()->unlock( (*it).resource() ); 00071 } 00072 00073 mAddresseeList.clear(); 00074 00075 return true; 00076 } 00077 00078 bool PwDeleteCommand::redo() 00079 { 00080 KABC::Addressee addr; 00081 KABC::Addressee::List::Iterator addrIt; 00082 00083 QStringList::Iterator it; 00084 for ( it = mUIDList.begin(); it != mUIDList.end(); ++it ) { 00085 addr = addressBook()->findByUid( *it ); 00086 lock()->lock( addr.resource() ); 00087 mAddresseeList.append( addr ); 00088 AddresseeConfig cfg( addr ); 00089 cfg.remove(); 00090 } 00091 00092 for ( addrIt = mAddresseeList.begin(); addrIt != mAddresseeList.end(); ++addrIt ) { 00093 addressBook()->removeAddressee( *addrIt ); 00094 lock()->unlock( (*addrIt).resource() ); 00095 } 00096 00097 return true; 00098 } 00099 00101 // PwPaste Methods 00102 00103 PwPasteCommand::PwPasteCommand( KAB::Core *core, 00104 const KABC::Addressee::List &list ) 00105 : Command( core->addressBook() ), mCore( core ), mAddresseeList( list ) 00106 { 00107 redo(); 00108 } 00109 00110 QString PwPasteCommand::name() 00111 { 00112 return i18n( "Paste" ); 00113 } 00114 00115 bool PwPasteCommand::undo() 00116 { 00117 KABC::Addressee::List::Iterator it; 00118 00119 // lock resources 00120 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) 00121 lock()->lock( (*it).resource() ); 00122 00123 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) { 00124 addressBook()->removeAddressee( *it ); 00125 lock()->unlock( (*it).resource() ); 00126 } 00127 00128 return true; 00129 } 00130 00131 bool PwPasteCommand::redo() 00132 { 00133 QStringList uids; 00134 KABC::Addressee::List::Iterator it; 00135 00136 // lock resources 00137 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) 00138 lock()->lock( (*it).resource() ); 00139 00140 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) { 00141 /* we have to set a new uid for the contact, otherwise insertAddressee() 00142 ignore it. 00143 */ 00144 (*it).setUid( KApplication::randomString( 10 ) ); 00145 uids.append( (*it).uid() ); 00146 addressBook()->insertAddressee( *it ); 00147 lock()->unlock( (*it).resource() ); 00148 } 00149 00150 QStringList::Iterator uidIt; 00151 for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt ) 00152 mCore->editContact( *uidIt ); 00153 00154 return true; 00155 } 00156 00158 // PwNew Methods 00159 00160 PwNewCommand::PwNewCommand( KABC::AddressBook *ab, const KABC::Addressee &addr ) 00161 : Command( ab ), mAddr( addr ) 00162 { 00163 redo(); 00164 } 00165 00166 PwNewCommand::~PwNewCommand() 00167 { 00168 } 00169 00170 QString PwNewCommand::name() 00171 { 00172 return i18n( "New Contact" ); 00173 } 00174 00175 bool PwNewCommand::undo() 00176 { 00177 lock()->lock( mAddr.resource() ); 00178 addressBook()->removeAddressee( mAddr ); 00179 lock()->unlock( mAddr.resource() ); 00180 00181 return true; 00182 } 00183 00184 bool PwNewCommand::redo() 00185 { 00186 lock()->lock( mAddr.resource() ); 00187 addressBook()->insertAddressee( mAddr ); 00188 lock()->unlock( mAddr.resource() ); 00189 00190 return true; 00191 } 00192 00194 // PwEdit Methods 00195 00196 PwEditCommand::PwEditCommand( KABC::AddressBook *ab, 00197 const KABC::Addressee &oldAddr, 00198 const KABC::Addressee &newAddr ) 00199 : Command( ab ), mOldAddr( oldAddr ), mNewAddr( newAddr ) 00200 { 00201 redo(); 00202 } 00203 00204 PwEditCommand::~PwEditCommand() 00205 { 00206 } 00207 00208 QString PwEditCommand::name() 00209 { 00210 return i18n( "Entry Edit" ); 00211 } 00212 00213 bool PwEditCommand::undo() 00214 { 00215 lock()->lock( mOldAddr.resource() ); 00216 addressBook()->insertAddressee( mOldAddr ); 00217 lock()->unlock( mOldAddr.resource() ); 00218 00219 return true; 00220 } 00221 00222 bool PwEditCommand::redo() 00223 { 00224 lock()->lock( mNewAddr.resource() ); 00225 addressBook()->insertAddressee( mNewAddr ); 00226 lock()->unlock( mNewAddr.resource() ); 00227 00228 return true; 00229 } 00230 00232 // PwCut Methods 00233 00234 PwCutCommand::PwCutCommand( KABC::AddressBook *ab, const QStringList &uidList ) 00235 : Command( ab ), mUIDList( uidList ) 00236 { 00237 redo(); 00238 } 00239 00240 QString PwCutCommand::name() 00241 { 00242 return i18n( "Cut" ); 00243 } 00244 00245 bool PwCutCommand::undo() 00246 { 00247 KABC::Addressee::List::Iterator it; 00248 00249 // lock resources 00250 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) 00251 lock()->lock( (*it).resource() ); 00252 00253 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) { 00254 addressBook()->insertAddressee( *it ); 00255 lock()->unlock( (*it).resource() ); 00256 } 00257 00258 mAddresseeList.clear(); 00259 00260 QClipboard *cb = QApplication::clipboard(); 00261 kapp->processEvents(); 00262 cb->setText( mOldText ); 00263 00264 return true; 00265 } 00266 00267 bool PwCutCommand::redo() 00268 { 00269 KABC::Addressee addr; 00270 KABC::Addressee::List::Iterator addrIt; 00271 00272 QStringList::Iterator it; 00273 for ( it = mUIDList.begin(); it != mUIDList.end(); ++it ) { 00274 addr = addressBook()->findByUid( *it ); 00275 mAddresseeList.append( addr ); 00276 lock()->lock( addr.resource() ); 00277 } 00278 00279 for ( addrIt = mAddresseeList.begin(); addrIt != mAddresseeList.end(); ++addrIt ) { 00280 addressBook()->removeAddressee( *addrIt ); 00281 lock()->unlock( addr.resource() ); 00282 } 00283 00284 // Convert to clipboard 00285 mClipText = AddresseeUtil::addresseesToClipboard( mAddresseeList ); 00286 00287 QClipboard *cb = QApplication::clipboard(); 00288 mOldText = cb->text(); 00289 kapp->processEvents(); 00290 cb->setText( mClipText ); 00291 00292 return true; 00293 }
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:05 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003