summaryrefslogtreecommitdiffabout
path: root/kaddressbook/undocmds.cpp
Unidiff
Diffstat (limited to 'kaddressbook/undocmds.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/undocmds.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/kaddressbook/undocmds.cpp b/kaddressbook/undocmds.cpp
index 5fbeec3..5807dc0 100644
--- a/kaddressbook/undocmds.cpp
+++ b/kaddressbook/undocmds.cpp
@@ -1,241 +1,242 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (C) 1999 Don Sanders <sanders@kde.org> 3 Copyright (C) 1999 Don Sanders <sanders@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qtextstream.h> 24#include <qtextstream.h>
25 25
26#include <qapplication.h> 26#include <qapplication.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28 28
29#include <klocale.h> 29#include <klocale.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include <kapplication.h> 31#include <kapplication.h>
32#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
33 33
34#include "addresseeutil.h" 34#include "addresseeutil.h"
35#include "addresseeconfig.h" 35#include "addresseeconfig.h"
36#include "kabcore.h" 36#include "kabcore.h"
37 37
38#include "undocmds.h" 38#include "undocmds.h"
39 39extern bool pasteWithNewUid;
40///////////////////////////////// 40/////////////////////////////////
41// PwDelete Methods 41// PwDelete Methods
42 42
43PwDeleteCommand::PwDeleteCommand(KABC::AddressBook *doc, 43PwDeleteCommand::PwDeleteCommand(KABC::AddressBook *doc,
44 const QStringList &uidList) 44 const QStringList &uidList)
45 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList) 45 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList)
46{ 46{
47 redo(); 47 redo();
48} 48}
49 49
50PwDeleteCommand::~PwDeleteCommand() 50PwDeleteCommand::~PwDeleteCommand()
51{ 51{
52} 52}
53 53
54QString PwDeleteCommand::name() 54QString PwDeleteCommand::name()
55{ 55{
56 return i18n( "Delete" ); 56 return i18n( "Delete" );
57} 57}
58 58
59void PwDeleteCommand::undo() 59void PwDeleteCommand::undo()
60{ 60{
61 // Put it back in the document 61 // Put it back in the document
62 KABC::Addressee::List::Iterator iter; 62 KABC::Addressee::List::Iterator iter;
63 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter) 63 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
64 { 64 {
65 mDocument->insertAddressee(*iter); 65 mDocument->insertAddressee(*iter);
66 } 66 }
67 67
68 mAddresseeList.clear(); 68 mAddresseeList.clear();
69} 69}
70 70
71void PwDeleteCommand::redo() 71void PwDeleteCommand::redo()
72{ 72{
73 // Just remove it from the document. This is enough to make the user 73 // Just remove it from the document. This is enough to make the user
74 // Think the item has been deleted 74 // Think the item has been deleted
75 KABC::Addressee a; 75 KABC::Addressee a;
76 QStringList::Iterator iter; 76 QStringList::Iterator iter;
77 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter) 77 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
78 { 78 {
79 a = mDocument->findByUid(*iter); 79 a = mDocument->findByUid(*iter);
80 mDocument->removeAddressee(a); 80 mDocument->removeAddressee(a);
81 mAddresseeList.append(a); 81 mAddresseeList.append(a);
82 AddresseeConfig::instance()->remove(a.uid()); 82 AddresseeConfig::instance()->remove(a.uid());
83 } 83 }
84} 84}
85 85
86///////////////////////////////// 86/////////////////////////////////
87// PwPaste Methods 87// PwPaste Methods
88 88
89PwPasteCommand::PwPasteCommand( KABCore *core, const KABC::Addressee::List &list ) 89PwPasteCommand::PwPasteCommand( KABCore *core, const KABC::Addressee::List &list )
90 : Command(), mCore( core ), mAddresseeList( list ) 90 : Command(), mCore( core ), mAddresseeList( list )
91{ 91{
92 redo(); 92 redo();
93} 93}
94 94
95QString PwPasteCommand::name() 95QString PwPasteCommand::name()
96{ 96{
97 return i18n( "Paste" ); 97 return i18n( "Paste" );
98} 98}
99 99
100void PwPasteCommand::undo() 100void PwPasteCommand::undo()
101{ 101{
102 KABC::Addressee::List::Iterator it; 102 KABC::Addressee::List::Iterator it;
103 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) 103 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it )
104 mCore->addressBook()->removeAddressee( *it ); 104 mCore->addressBook()->removeAddressee( *it );
105} 105}
106 106
107void PwPasteCommand::redo() 107void PwPasteCommand::redo()
108{ 108{
109 QStringList uids; 109 QStringList uids;
110 KABC::Addressee::List::Iterator it; 110 KABC::Addressee::List::Iterator it;
111 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) { 111 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) {
112 /* we have to set a new uid for the contact, otherwise insertAddressee() 112 /* we have to set a new uid for the contact, otherwise insertAddressee()
113 ignore it. 113 ignore it.
114 */ 114 */
115 (*it).setUid( KApplication::randomString( 10 ) ); 115 if ( pasteWithNewUid )
116 (*it).setUid( KApplication::randomString( 10 ) );
116 uids.append( (*it).uid() ); 117 uids.append( (*it).uid() );
117 mCore->addressBook()->insertAddressee( *it ); 118 mCore->addressBook()->insertAddressee( *it );
118 } 119 }
119 if ( uids.count() < 4 ) { 120 if ( uids.count() < 4 ) {
120 QStringList::Iterator uidIt; 121 QStringList::Iterator uidIt;
121 for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt ) 122 for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt )
122 mCore->editContact( *uidIt ); 123 mCore->editContact( *uidIt );
123 } 124 }
124} 125}
125 126
126///////////////////////////////// 127/////////////////////////////////
127// PwNew Methods 128// PwNew Methods
128 129
129PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a ) 130PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a )
130 : Command(), mDocument( doc ), mA( a ) 131 : Command(), mDocument( doc ), mA( a )
131{ 132{
132 mDocument->insertAddressee(mA); 133 mDocument->insertAddressee(mA);
133} 134}
134 135
135PwNewCommand::~PwNewCommand() 136PwNewCommand::~PwNewCommand()
136{ 137{
137} 138}
138 139
139QString PwNewCommand::name() 140QString PwNewCommand::name()
140{ 141{
141 return i18n( "New Contact" ); 142 return i18n( "New Contact" );
142} 143}
143 144
144void PwNewCommand::undo() 145void PwNewCommand::undo()
145{ 146{
146 mDocument->removeAddressee( mA ); 147 mDocument->removeAddressee( mA );
147} 148}
148 149
149void PwNewCommand::redo() 150void PwNewCommand::redo()
150{ 151{
151 mDocument->insertAddressee( mA ); 152 mDocument->insertAddressee( mA );
152} 153}
153 154
154///////////////////////////////// 155/////////////////////////////////
155// PwEdit Methods 156// PwEdit Methods
156 157
157PwEditCommand::PwEditCommand(KABC::AddressBook *doc, 158PwEditCommand::PwEditCommand(KABC::AddressBook *doc,
158 const KABC::Addressee &oldA, 159 const KABC::Addressee &oldA,
159 const KABC::Addressee &newA ) 160 const KABC::Addressee &newA )
160 : Command(), mDocument(doc), mOldA(oldA), mNewA(newA) 161 : Command(), mDocument(doc), mOldA(oldA), mNewA(newA)
161{ 162{
162 redo(); 163 redo();
163} 164}
164 165
165PwEditCommand::~PwEditCommand() 166PwEditCommand::~PwEditCommand()
166{ 167{
167} 168}
168 169
169QString PwEditCommand::name() 170QString PwEditCommand::name()
170{ 171{
171 return i18n( "Entry Edit" ); 172 return i18n( "Entry Edit" );
172} 173}
173 174
174void PwEditCommand::undo() 175void PwEditCommand::undo()
175{ 176{
176 mDocument->insertAddressee(mOldA); 177 mDocument->insertAddressee(mOldA);
177} 178}
178 179
179void PwEditCommand::redo() 180void PwEditCommand::redo()
180{ 181{
181 mDocument->insertAddressee(mNewA); 182 mDocument->insertAddressee(mNewA);
182} 183}
183 184
184///////////////////////////////// 185/////////////////////////////////
185// PwCut Methods 186// PwCut Methods
186 187
187PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList) 188PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList)
188 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList), 189 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList),
189 mClipText(), mOldText() 190 mClipText(), mOldText()
190{ 191{
191 redo(); 192 redo();
192} 193}
193 194
194QString PwCutCommand::name() 195QString PwCutCommand::name()
195{ 196{
196 return i18n( "Cut" ); 197 return i18n( "Cut" );
197} 198}
198 199
199void PwCutCommand::undo() 200void PwCutCommand::undo()
200{ 201{
201 KABC::Addressee::List::Iterator iter; 202 KABC::Addressee::List::Iterator iter;
202 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter) 203 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
203 { 204 {
204 mDocument->insertAddressee(*iter); 205 mDocument->insertAddressee(*iter);
205 } 206 }
206 mAddresseeList.clear(); 207 mAddresseeList.clear();
207 208
208 QClipboard *cb = QApplication::clipboard(); 209 QClipboard *cb = QApplication::clipboard();
209//US 210//US
210#ifndef KAB_EMBEDDED 211#ifndef KAB_EMBEDDED
211 kapp->processEvents(); 212 kapp->processEvents();
212#else //KAB_EMBEDDED 213#else //KAB_EMBEDDED
213 qApp->processEvents(); 214 qApp->processEvents();
214#endif //KAB_EMBEDDED 215#endif //KAB_EMBEDDED
215 cb->setText( mOldText ); 216 cb->setText( mOldText );
216} 217}
217 218
218void PwCutCommand::redo() 219void PwCutCommand::redo()
219{ 220{
220 KABC::Addressee a; 221 KABC::Addressee a;
221 QStringList::Iterator iter; 222 QStringList::Iterator iter;
222 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter) 223 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
223 { 224 {
224 a = mDocument->findByUid(*iter); 225 a = mDocument->findByUid(*iter);
225 mDocument->removeAddressee(a); 226 mDocument->removeAddressee(a);
226 mAddresseeList.append(a); 227 mAddresseeList.append(a);
227 } 228 }
228 229
229 // Convert to clipboard 230 // Convert to clipboard
230 mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList); 231 mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList);
231 232
232 QClipboard *cb = QApplication::clipboard(); 233 QClipboard *cb = QApplication::clipboard();
233 mOldText = cb->text(); 234 mOldText = cb->text();
234//US 235//US
235#ifndef KAB_EMBEDDED 236#ifndef KAB_EMBEDDED
236 kapp->processEvents(); 237 kapp->processEvents();
237#else //KAB_EMBEDDED 238#else //KAB_EMBEDDED
238 qApp->processEvents(); 239 qApp->processEvents();
239#endif //KAB_EMBEDDED 240#endif //KAB_EMBEDDED
240 cb->setText( mClipText ); 241 cb->setText( mClipText );
241} 242}