-rw-r--r-- | kaddressbook/undocmds.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kaddressbook/undocmds.cpp b/kaddressbook/undocmds.cpp index 5807dc0..e900b00 100644 --- a/kaddressbook/undocmds.cpp +++ b/kaddressbook/undocmds.cpp | |||
@@ -1,242 +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 <q3textstream.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 | extern bool pasteWithNewUid; | 39 | extern bool pasteWithNewUid; |
40 | ///////////////////////////////// | 40 | ///////////////////////////////// |
41 | // PwDelete Methods | 41 | // PwDelete Methods |
42 | 42 | ||
43 | PwDeleteCommand::PwDeleteCommand(KABC::AddressBook *doc, | 43 | PwDeleteCommand::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 | ||
50 | PwDeleteCommand::~PwDeleteCommand() | 50 | PwDeleteCommand::~PwDeleteCommand() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | QString PwDeleteCommand::name() | 54 | QString PwDeleteCommand::name() |
55 | { | 55 | { |
56 | return i18n( "Delete" ); | 56 | return i18n( "Delete" ); |
57 | } | 57 | } |
58 | 58 | ||
59 | void PwDeleteCommand::undo() | 59 | void 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 | ||
71 | void PwDeleteCommand::redo() | 71 | void 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 | ||
89 | PwPasteCommand::PwPasteCommand( KABCore *core, const KABC::Addressee::List &list ) | 89 | PwPasteCommand::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 | ||
95 | QString PwPasteCommand::name() | 95 | QString PwPasteCommand::name() |
96 | { | 96 | { |
97 | return i18n( "Paste" ); | 97 | return i18n( "Paste" ); |
98 | } | 98 | } |
99 | 99 | ||
100 | void PwPasteCommand::undo() | 100 | void 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 | ||
107 | void PwPasteCommand::redo() | 107 | void 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 | if ( pasteWithNewUid ) | 115 | if ( pasteWithNewUid ) |
116 | (*it).setUid( KApplication::randomString( 10 ) ); | 116 | (*it).setUid( KApplication::randomString( 10 ) ); |
117 | uids.append( (*it).uid() ); | 117 | uids.append( (*it).uid() ); |
118 | mCore->addressBook()->insertAddressee( *it ); | 118 | mCore->addressBook()->insertAddressee( *it ); |
119 | } | 119 | } |
120 | if ( uids.count() < 4 ) { | 120 | if ( uids.count() < 4 ) { |
121 | QStringList::Iterator uidIt; | 121 | QStringList::Iterator uidIt; |
122 | for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt ) | 122 | for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt ) |
123 | mCore->editContact( *uidIt ); | 123 | mCore->editContact( *uidIt ); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | ///////////////////////////////// | 127 | ///////////////////////////////// |
128 | // PwNew Methods | 128 | // PwNew Methods |
129 | 129 | ||
130 | PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a ) | 130 | PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a ) |
131 | : Command(), mDocument( doc ), mA( a ) | 131 | : Command(), mDocument( doc ), mA( a ) |
132 | { | 132 | { |
133 | mDocument->insertAddressee(mA); | 133 | mDocument->insertAddressee(mA); |
134 | } | 134 | } |
135 | 135 | ||
136 | PwNewCommand::~PwNewCommand() | 136 | PwNewCommand::~PwNewCommand() |
137 | { | 137 | { |
138 | } | 138 | } |
139 | 139 | ||
140 | QString PwNewCommand::name() | 140 | QString PwNewCommand::name() |
141 | { | 141 | { |
142 | return i18n( "New Contact" ); | 142 | return i18n( "New Contact" ); |
143 | } | 143 | } |
144 | 144 | ||
145 | void PwNewCommand::undo() | 145 | void PwNewCommand::undo() |
146 | { | 146 | { |
147 | mDocument->removeAddressee( mA ); | 147 | mDocument->removeAddressee( mA ); |
148 | } | 148 | } |
149 | 149 | ||
150 | void PwNewCommand::redo() | 150 | void PwNewCommand::redo() |
151 | { | 151 | { |
152 | mDocument->insertAddressee( mA ); | 152 | mDocument->insertAddressee( mA ); |
153 | } | 153 | } |
154 | 154 | ||
155 | ///////////////////////////////// | 155 | ///////////////////////////////// |
156 | // PwEdit Methods | 156 | // PwEdit Methods |
157 | 157 | ||
158 | PwEditCommand::PwEditCommand(KABC::AddressBook *doc, | 158 | PwEditCommand::PwEditCommand(KABC::AddressBook *doc, |
159 | const KABC::Addressee &oldA, | 159 | const KABC::Addressee &oldA, |
160 | const KABC::Addressee &newA ) | 160 | const KABC::Addressee &newA ) |
161 | : Command(), mDocument(doc), mOldA(oldA), mNewA(newA) | 161 | : Command(), mDocument(doc), mOldA(oldA), mNewA(newA) |
162 | { | 162 | { |
163 | redo(); | 163 | redo(); |
164 | } | 164 | } |
165 | 165 | ||
166 | PwEditCommand::~PwEditCommand() | 166 | PwEditCommand::~PwEditCommand() |
167 | { | 167 | { |
168 | } | 168 | } |
169 | 169 | ||
170 | QString PwEditCommand::name() | 170 | QString PwEditCommand::name() |
171 | { | 171 | { |
172 | return i18n( "Entry Edit" ); | 172 | return i18n( "Entry Edit" ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void PwEditCommand::undo() | 175 | void PwEditCommand::undo() |
176 | { | 176 | { |
177 | mDocument->insertAddressee(mOldA); | 177 | mDocument->insertAddressee(mOldA); |
178 | } | 178 | } |
179 | 179 | ||
180 | void PwEditCommand::redo() | 180 | void PwEditCommand::redo() |
181 | { | 181 | { |
182 | mDocument->insertAddressee(mNewA); | 182 | mDocument->insertAddressee(mNewA); |
183 | } | 183 | } |
184 | 184 | ||
185 | ///////////////////////////////// | 185 | ///////////////////////////////// |
186 | // PwCut Methods | 186 | // PwCut Methods |
187 | 187 | ||
188 | PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList) | 188 | PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList) |
189 | : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList), | 189 | : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList), |
190 | mClipText(), mOldText() | 190 | mClipText(), mOldText() |
191 | { | 191 | { |
192 | redo(); | 192 | redo(); |
193 | } | 193 | } |
194 | 194 | ||
195 | QString PwCutCommand::name() | 195 | QString PwCutCommand::name() |
196 | { | 196 | { |
197 | return i18n( "Cut" ); | 197 | return i18n( "Cut" ); |
198 | } | 198 | } |
199 | 199 | ||
200 | void PwCutCommand::undo() | 200 | void PwCutCommand::undo() |
201 | { | 201 | { |
202 | KABC::Addressee::List::Iterator iter; | 202 | KABC::Addressee::List::Iterator iter; |
203 | for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter) | 203 | for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter) |
204 | { | 204 | { |
205 | mDocument->insertAddressee(*iter); | 205 | mDocument->insertAddressee(*iter); |
206 | } | 206 | } |
207 | mAddresseeList.clear(); | 207 | mAddresseeList.clear(); |
208 | 208 | ||
209 | QClipboard *cb = QApplication::clipboard(); | 209 | QClipboard *cb = QApplication::clipboard(); |
210 | //US | 210 | //US |
211 | #ifndef KAB_EMBEDDED | 211 | #ifndef KAB_EMBEDDED |
212 | kapp->processEvents(); | 212 | kapp->processEvents(); |
213 | #else //KAB_EMBEDDED | 213 | #else //KAB_EMBEDDED |
214 | qApp->processEvents(); | 214 | qApp->processEvents(); |
215 | #endif //KAB_EMBEDDED | 215 | #endif //KAB_EMBEDDED |
216 | cb->setText( mOldText ); | 216 | cb->setText( mOldText ); |
217 | } | 217 | } |
218 | 218 | ||
219 | void PwCutCommand::redo() | 219 | void PwCutCommand::redo() |
220 | { | 220 | { |
221 | KABC::Addressee a; | 221 | KABC::Addressee a; |
222 | QStringList::Iterator iter; | 222 | QStringList::Iterator iter; |
223 | for (iter = mUidList.begin(); iter != mUidList.end(); ++iter) | 223 | for (iter = mUidList.begin(); iter != mUidList.end(); ++iter) |
224 | { | 224 | { |
225 | a = mDocument->findByUid(*iter); | 225 | a = mDocument->findByUid(*iter); |
226 | mDocument->removeAddressee(a); | 226 | mDocument->removeAddressee(a); |
227 | mAddresseeList.append(a); | 227 | mAddresseeList.append(a); |
228 | } | 228 | } |
229 | 229 | ||
230 | // Convert to clipboard | 230 | // Convert to clipboard |
231 | mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList); | 231 | mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList); |
232 | 232 | ||
233 | QClipboard *cb = QApplication::clipboard(); | 233 | QClipboard *cb = QApplication::clipboard(); |
234 | mOldText = cb->text(); | 234 | mOldText = cb->text(); |
235 | //US | 235 | //US |
236 | #ifndef KAB_EMBEDDED | 236 | #ifndef KAB_EMBEDDED |
237 | kapp->processEvents(); | 237 | kapp->processEvents(); |
238 | #else //KAB_EMBEDDED | 238 | #else //KAB_EMBEDDED |
239 | qApp->processEvents(); | 239 | qApp->processEvents(); |
240 | #endif //KAB_EMBEDDED | 240 | #endif //KAB_EMBEDDED |
241 | cb->setText( mClipText ); | 241 | cb->setText( mClipText ); |
242 | } | 242 | } |