• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

undocmds.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KAddressBook.
00003     Copyright (C) 1999 Don Sanders <sanders@kde.org>
00004                   2005 Tobias Koenig <tokoe@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <QtGui/QApplication>
00026 #include <QtGui/QClipboard>
00027 
00028 #include <kapplication.h>
00029 #include <klocale.h>
00030 #include <krandom.h>
00031 
00032 #include "addresseeconfig.h"
00033 #include "addresseeutil.h"
00034 #include "core.h"
00035 #include "kablock.h"
00036 
00037 #include "undocmds.h"
00038 
00039 DeleteCommand::DeleteCommand( KABC::AddressBook *addressBook,
00040                               const QStringList &uidList)
00041   : Command( addressBook ), mUIDList( uidList )
00042 {
00043 }
00044 
00045 QString DeleteCommand::text() const
00046 {
00047   return i18np( "Delete Contact", "Delete %1 Contacts", mUIDList.count() );
00048 }
00049 
00050 void DeleteCommand::undo()
00051 {
00052   // Put it back in the document
00053   KABC::Addressee::List::ConstIterator it;
00054   const KABC::Addressee::List::ConstIterator endIt( mAddresseeList.end() );
00055 
00056   // lock resources
00057   for ( it = mAddresseeList.begin(); it != endIt; ++it )
00058     lock()->lock( (*it).resource() );
00059 
00060   for ( it = mAddresseeList.begin(); it != endIt; ++it ) {
00061     addressBook()->insertAddressee( *it );
00062     lock()->unlock( (*it).resource() );
00063   }
00064 
00065   mAddresseeList.clear();
00066 }
00067 
00068 void DeleteCommand::redo()
00069 {
00070   KABC::Addressee addr;
00071 
00072   QStringList::ConstIterator it;
00073   const QStringList::ConstIterator endIt( mUIDList.end() );
00074   for ( it = mUIDList.begin(); it != endIt; ++it ) {
00075     addr = addressBook()->findByUid( *it );
00076     lock()->lock( addr.resource() );
00077     mAddresseeList.append( addr );
00078     AddresseeConfig cfg( addr );
00079     cfg.remove();
00080   }
00081 
00082   KABC::Addressee::List::ConstIterator addrIt;
00083   const KABC::Addressee::List::ConstIterator addrEndIt( mAddresseeList.end() );
00084   for ( addrIt = mAddresseeList.begin(); addrIt != addrEndIt; ++addrIt ) {
00085     addressBook()->removeAddressee( *addrIt );
00086     lock()->unlock( (*addrIt).resource() );
00087   }
00088 }
00089 
00090 
00091 PasteCommand::PasteCommand( KAB::Core *core, const KABC::Addressee::List &addressees )
00092   : Command( core->addressBook() ), mAddresseeList( addressees ), mCore( core )
00093 {
00094 }
00095 
00096 QString PasteCommand::text() const
00097 {
00098   return i18np( "Paste Contact", "Paste %1 Contacts", mAddresseeList.count() );
00099 }
00100 
00101 void PasteCommand::undo()
00102 {
00103   KABC::Addressee::List::ConstIterator it;
00104   const KABC::Addressee::List::ConstIterator endIt( mAddresseeList.end() );
00105 
00106   // lock resources
00107   for ( it = mAddresseeList.begin(); it != endIt; ++it )
00108     lock()->lock( (*it).resource() );
00109 
00110   for ( it = mAddresseeList.begin(); it != endIt; ++it ) {
00111     addressBook()->removeAddressee( *it );
00112     lock()->unlock( (*it).resource() );
00113   }
00114 }
00115 
00116 void PasteCommand::redo()
00117 {
00118   QStringList uids;
00119 
00120   KABC::Addressee::List::ConstIterator constIt;
00121   const KABC::Addressee::List::ConstIterator constEndIt( mAddresseeList.end() );
00122 
00123   // lock resources
00124   for ( constIt = mAddresseeList.begin(); constIt != constEndIt; ++constIt )
00125     lock()->lock( (*constIt).resource() );
00126 
00127   KABC::Addressee::List::Iterator it;
00128   const KABC::Addressee::List::Iterator endIt( mAddresseeList.end() );
00129   for ( it = mAddresseeList.begin(); it != endIt; ++it ) {
00134     (*it).setUid( KRandom::randomString( 10 ) );
00135     uids.append( (*it).uid() );
00136     addressBook()->insertAddressee( *it );
00137     lock()->unlock( (*it).resource() );
00138   }
00139 
00140   QStringList::ConstIterator uidIt;
00141   const QStringList::ConstIterator uidEndIt( uids.end() );
00142   for ( uidIt = uids.begin(); uidIt != uidEndIt; ++uidIt )
00143     mCore->editContact( *uidIt );
00144 }
00145 
00146 
00147 NewCommand::NewCommand( KABC::AddressBook *addressBook, const KABC::Addressee::List &addressees )
00148   : Command( addressBook ), mAddresseeList( addressees )
00149 {
00150 }
00151 
00152 QString NewCommand::text() const
00153 {
00154   return i18np( "New Contact", "New %1 Contacts", mAddresseeList.count() );
00155 }
00156 
00157 void NewCommand::undo()
00158 {
00159   KABC::Addressee::List::ConstIterator it;
00160   const KABC::Addressee::List::ConstIterator endIt( mAddresseeList.end() );
00161 
00162   // lock resources
00163   for ( it = mAddresseeList.begin(); it != endIt; ++it )
00164     lock()->lock( (*it).resource() );
00165 
00166   for ( it = mAddresseeList.begin(); it != endIt; ++it ) {
00167     addressBook()->removeAddressee( *it );
00168     lock()->unlock( (*it).resource() );
00169   }
00170 }
00171 
00172 void NewCommand::redo()
00173 {
00174   KABC::Addressee::List::Iterator it;
00175   const KABC::Addressee::List::Iterator endIt( mAddresseeList.end() );
00176 
00177   // lock resources
00178   for ( it = mAddresseeList.begin(); it != endIt; ++it )
00179     lock()->lock( (*it).resource() );
00180 
00181   for ( it = mAddresseeList.begin(); it != endIt; ++it ) {
00182     addressBook()->insertAddressee( *it );
00183     lock()->unlock( (*it).resource() );
00184   }
00185 }
00186 
00187 
00188 EditCommand::EditCommand( KABC::AddressBook *addressBook,
00189                           const KABC::Addressee &oldAddressee,
00190                           const KABC::Addressee &newAddressee )
00191   : Command( addressBook ),
00192     mOldAddressee( oldAddressee ), mNewAddressee( newAddressee )
00193 {
00194 }
00195 
00196 QString EditCommand::text() const
00197 {
00198   return i18n( "Edit Contact" );
00199 }
00200 
00201 void EditCommand::undo()
00202 {
00203   lock()->lock( mOldAddressee.resource() );
00204   addressBook()->insertAddressee( mOldAddressee );
00205   lock()->unlock( mOldAddressee.resource() );
00206 }
00207 
00208 void EditCommand::redo()
00209 {
00210   lock()->lock( mNewAddressee.resource() );
00211   addressBook()->insertAddressee( mNewAddressee );
00212   lock()->unlock( mNewAddressee.resource() );
00213 }
00214 
00215 
00216 CutCommand::CutCommand( KABC::AddressBook *addressBook, const QStringList &uidList )
00217   : Command( addressBook ), mUIDList( uidList )
00218 {
00219 }
00220 
00221 QString CutCommand::text() const
00222 {
00223   return i18np( "Cut Contact", "Cut %1 Contacts", mUIDList.count() );
00224 }
00225 
00226 void CutCommand::undo()
00227 {
00228   KABC::Addressee::List::ConstIterator it;
00229   const KABC::Addressee::List::ConstIterator endIt( mAddresseeList.end() );
00230 
00231   // lock resources
00232   for ( it = mAddresseeList.begin(); it != endIt; ++it )
00233     lock()->lock( (*it).resource() );
00234 
00235   for ( it = mAddresseeList.begin(); it != endIt; ++it ) {
00236     addressBook()->insertAddressee( *it );
00237     lock()->unlock( (*it).resource() );
00238   }
00239 
00240   mAddresseeList.clear();
00241 
00242   QClipboard *cb = QApplication::clipboard();
00243   kapp->processEvents();
00244   cb->setText( mOldText );
00245 }
00246 
00247 void CutCommand::redo()
00248 {
00249   KABC::Addressee addr;
00250 
00251   QStringList::ConstIterator it;
00252   const QStringList::ConstIterator endIt( mUIDList.end() );
00253   for ( it = mUIDList.begin(); it != endIt; ++it ) {
00254     addr = addressBook()->findByUid( *it );
00255     mAddresseeList.append( addr );
00256     lock()->lock( addr.resource() );
00257   }
00258 
00259   KABC::Addressee::List::ConstIterator addrIt;
00260   const KABC::Addressee::List::ConstIterator addrEndIt( mAddresseeList.end() );
00261   for ( addrIt = mAddresseeList.begin(); addrIt != addrEndIt; ++addrIt ) {
00262     addressBook()->removeAddressee( *addrIt );
00263     lock()->unlock( addr.resource() );
00264   }
00265 
00266   // Convert to clipboard
00267   mClipText = AddresseeUtil::addresseesToClipboard( mAddresseeList );
00268 
00269   QClipboard *cb = QApplication::clipboard();
00270   mOldText = cb->text();
00271   kapp->processEvents();
00272   cb->setText( mClipText );
00273 }

kaddressbook

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal